|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
ADO.NET Problem write or wrongif I am using it right or not? Imports System.Data.sqlclient Imports System.Data Public Class Form1 Inherits System.Windows.Forms.Form Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim conn As New SqlConnection("Server=apw-db;" & _ "DataBase=APW-System; Integrated Security=SSPI") Dim sqlstr As String = "SELECT * FROM sysName" Dim da As SqlDataAdapter Dim ds As New DataSet da = New SqlDataAdapter(sqlstr, conn) da.Fill(ds) Dim dt As DataTable = ds.Tables(0) MsgBox(dt.Rows.Item("sysName")) 'trying to show what is in field End Sub End Class I am using sql 2005 and vb 2005
Show quoteHide quote "Andrew" wrote: > I am simple tryint to learn how to use the ADO.NET code. Can anybody tell me > if I am using it right or not? > > Imports System.Data.sqlclient > Imports System.Data > > Public Class Form1 > > Inherits System.Windows.Forms.Form > > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As > System.EventArgs) Handles Button1.Click > > Dim conn As New SqlConnection("Server=apw-db;" & _ > "DataBase=APW-System; Integrated Security=SSPI") > Dim sqlstr As String = "SELECT * FROM sysName" > Dim da As SqlDataAdapter > Dim ds As New DataSet > da = New SqlDataAdapter(sqlstr, conn) > da.Fill(ds) > Dim dt As DataTable = ds.Tables(0) > > MsgBox(dt.Rows.Item("sysName")) 'trying to show what is in field > > End Sub > End Class Andrew wrote:
> I am using sql 2005 and vb 2005 <snip>> > "Andrew" wrote: > > > I am simple tryint to learn how to use the ADO.NET code. Can anybody tell me > > if I am using it right or not? This worked for me: I first completely disregarded the several wizards that come with VB 2005 and tried my hand in creating a strongly-typed version of a database we have here. After struggling (and actually succeeding) with this approach for a few days, I reckoned I had enough control and knowledge of ADO.NET to give the designers a try. Currently I'm using the designers for most new apps -- they're actually cool, if you don't look under their dresses... =)) The experience with a hand-made strongly-typed db system tought me some lessons and gave me a broarder perspective of the ADO.NET engine workings. As they say, your mileage may vary. And it allowed me to understand enough of it (I guess) to make it easier to extend the functionality of the wizard generated items when necessary. HTH. Regards, Branco. Andrew,
Nothing wrong with in my idea, however I would do it in its simplest format in this way. > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As Dim da As new SqlDataAdapter(sqlstr, conn)> System.EventArgs) Handles Button1.Click > > Dim conn As New SqlConnection("Server=apw-db;" & _ > "DataBase=APW-System; Integrated Security=SSPI") > Dim sqlstr As String = "SELECT * FROM sysName" > Dim ds As New DataSet Try> da.Fill(ds) MessageBox.Show(ds.Tables(0).Rows.Item("sysName")) 'trying to show what is in field Catch ex as Exception MessageBox.Show(ex.ToString) End Try > End Sub I hope this helps,Cor Show quoteHide quote "Andrew" <And***@discussions.microsoft.com> schreef in bericht news:0355ADCB-BE94-4D60-882A-E5D9ABDACDCD@microsoft.com... >I am simple tryint to learn how to use the ADO.NET code. Can anybody tell >me > if I am using it right or not? > > Imports System.Data.sqlclient > Imports System.Data > > Public Class Form1 > > Inherits System.Windows.Forms.Form > > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As > System.EventArgs) Handles Button1.Click > > Dim conn As New SqlConnection("Server=apw-db;" & _ > "DataBase=APW-System; Integrated Security=SSPI") > Dim sqlstr As String = "SELECT * FROM sysName" > Dim da As SqlDataAdapter > Dim ds As New DataSet > da = New SqlDataAdapter(sqlstr, conn) > da.Fill(ds) > Dim dt As DataTable = ds.Tables(0) > > MsgBox(dt.Rows.Item("sysName")) 'trying to show what is in field > > End Sub > End Class when I put as you put I get an error : "System.data.datarow" cannot be
converted to string. when I put convert.tostring(ds.Tables(0).Rows.Item("sysName"))) I get a new message: system.nullfreferenceExecptoin: Object Reference not set to instaance of an Object. as windowsApplication1.form1.button1_click() app path ADodb.net\windowsaplication1\form1.vb:line71 I have one row with information in this table and the field is a nvarchar(max) with allow nulls checked. Show quoteHide quote "Cor Ligthert [MVP]" wrote: > Andrew, > > Nothing wrong with in my idea, however I would do it in its simplest format > in this way. > > > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As > > System.EventArgs) Handles Button1.Click > > > > Dim conn As New SqlConnection("Server=apw-db;" & _ > > "DataBase=APW-System; Integrated Security=SSPI") > > Dim sqlstr As String = "SELECT * FROM sysName" > Dim da As new SqlDataAdapter(sqlstr, conn) > > Dim ds As New DataSet > Try > > da.Fill(ds) > MessageBox.Show(ds.Tables(0).Rows.Item("sysName")) 'trying to show > what is in field > Catch ex as Exception > MessageBox.Show(ex.ToString) > End Try > > End Sub > > I hope this helps, > > Cor > > > "Andrew" <And***@discussions.microsoft.com> schreef in bericht > news:0355ADCB-BE94-4D60-882A-E5D9ABDACDCD@microsoft.com... > >I am simple tryint to learn how to use the ADO.NET code. Can anybody tell > >me > > if I am using it right or not? > > > > Imports System.Data.sqlclient > > Imports System.Data > > > > Public Class Form1 > > > > Inherits System.Windows.Forms.Form > > > > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As > > System.EventArgs) Handles Button1.Click > > > > Dim conn As New SqlConnection("Server=apw-db;" & _ > > "DataBase=APW-System; Integrated Security=SSPI") > > Dim sqlstr As String = "SELECT * FROM sysName" > > Dim da As SqlDataAdapter > > Dim ds As New DataSet > > da = New SqlDataAdapter(sqlstr, conn) > > da.Fill(ds) > > Dim dt As DataTable = ds.Tables(0) > > > > MsgBox(dt.Rows.Item("sysName")) 'trying to show what is in field > > > > End Sub > > End Class > > > Andrew,
Sorry, this can be Cstr(ds.Tables(0).Rows(0).Item("sysName")) ds.Tables(0).Rows(0).Item("sysName").ToString Ctype(ds.Tables(0).Rows(0).Item("sysName"),String) Most people including me use the ToString, I have typed it in the message, looking at the major points. I hope it will go now, again not tested just typed. Cor Show quoteHide quote "Andrew" <And***@discussions.microsoft.com> schreef in bericht news:077901A1-9479-4278-8E3C-37DEC01C7990@microsoft.com... > when I put as you put I get an error : "System.data.datarow" cannot be > converted to string. > > when I put convert.tostring(ds.Tables(0).Rows.Item("sysName"))) > > I get a new message: > > system.nullfreferenceExecptoin: Object Reference not set to instaance of > an > Object. > as windowsApplication1.form1.button1_click() app path > ADodb.net\windowsaplication1\form1.vb:line71 > > I have one row with information in this table and the field is a > nvarchar(max) with allow nulls checked. > > "Cor Ligthert [MVP]" wrote: > >> Andrew, >> >> Nothing wrong with in my idea, however I would do it in its simplest >> format >> in this way. >> >> > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As >> > System.EventArgs) Handles Button1.Click >> > >> > Dim conn As New SqlConnection("Server=apw-db;" & _ >> > "DataBase=APW-System; Integrated Security=SSPI") >> > Dim sqlstr As String = "SELECT * FROM sysName" >> Dim da As new SqlDataAdapter(sqlstr, conn) >> > Dim ds As New DataSet >> Try >> > da.Fill(ds) >> MessageBox.Show(ds.Tables(0).Rows.Item("sysName")) 'trying to >> show >> what is in field >> Catch ex as Exception >> MessageBox.Show(ex.ToString) >> End Try >> > End Sub >> >> I hope this helps, >> >> Cor >> >> >> "Andrew" <And***@discussions.microsoft.com> schreef in bericht >> news:0355ADCB-BE94-4D60-882A-E5D9ABDACDCD@microsoft.com... >> >I am simple tryint to learn how to use the ADO.NET code. Can anybody >> >tell >> >me >> > if I am using it right or not? >> > >> > Imports System.Data.sqlclient >> > Imports System.Data >> > >> > Public Class Form1 >> > >> > Inherits System.Windows.Forms.Form >> > >> > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As >> > System.EventArgs) Handles Button1.Click >> > >> > Dim conn As New SqlConnection("Server=apw-db;" & _ >> > "DataBase=APW-System; Integrated Security=SSPI") >> > Dim sqlstr As String = "SELECT * FROM sysName" >> > Dim da As SqlDataAdapter >> > Dim ds As New DataSet >> > da = New SqlDataAdapter(sqlstr, conn) >> > da.Fill(ds) >> > Dim dt As DataTable = ds.Tables(0) >> > >> > MsgBox(dt.Rows.Item("sysName")) 'trying to show what is in field >> > >> > End Sub >> > End Class >> >> >> I found one of the problems there was no (0) after Rows in my code, but now
when I execute I get the Exception error: system.NullreferenceExection: Object reference not set to an instance of an object. Show quoteHide quote "Cor Ligthert [MVP]" wrote: > Andrew, > > Sorry, this can be > Cstr(ds.Tables(0).Rows(0).Item("sysName")) > ds.Tables(0).Rows(0).Item("sysName").ToString > Ctype(ds.Tables(0).Rows(0).Item("sysName"),String) > > Most people including me use the ToString, > > I have typed it in the message, looking at the major points. > > I hope it will go now, again not tested just typed. > > Cor > > > "Andrew" <And***@discussions.microsoft.com> schreef in bericht > news:077901A1-9479-4278-8E3C-37DEC01C7990@microsoft.com... > > when I put as you put I get an error : "System.data.datarow" cannot be > > converted to string. > > > > when I put convert.tostring(ds.Tables(0).Rows.Item("sysName"))) > > > > I get a new message: > > > > system.nullfreferenceExecptoin: Object Reference not set to instaance of > > an > > Object. > > as windowsApplication1.form1.button1_click() app path > > ADodb.net\windowsaplication1\form1.vb:line71 > > > > I have one row with information in this table and the field is a > > nvarchar(max) with allow nulls checked. > > > > "Cor Ligthert [MVP]" wrote: > > > >> Andrew, > >> > >> Nothing wrong with in my idea, however I would do it in its simplest > >> format > >> in this way. > >> > >> > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As > >> > System.EventArgs) Handles Button1.Click > >> > > >> > Dim conn As New SqlConnection("Server=apw-db;" & _ > >> > "DataBase=APW-System; Integrated Security=SSPI") > >> > Dim sqlstr As String = "SELECT * FROM sysName" > >> Dim da As new SqlDataAdapter(sqlstr, conn) > >> > Dim ds As New DataSet > >> Try > >> > da.Fill(ds) > >> MessageBox.Show(ds.Tables(0).Rows.Item("sysName")) 'trying to > >> show > >> what is in field > >> Catch ex as Exception > >> MessageBox.Show(ex.ToString) > >> End Try > >> > End Sub > >> > >> I hope this helps, > >> > >> Cor > >> > >> > >> "Andrew" <And***@discussions.microsoft.com> schreef in bericht > >> news:0355ADCB-BE94-4D60-882A-E5D9ABDACDCD@microsoft.com... > >> >I am simple tryint to learn how to use the ADO.NET code. Can anybody > >> >tell > >> >me > >> > if I am using it right or not? > >> > > >> > Imports System.Data.sqlclient > >> > Imports System.Data > >> > > >> > Public Class Form1 > >> > > >> > Inherits System.Windows.Forms.Form > >> > > >> > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As > >> > System.EventArgs) Handles Button1.Click > >> > > >> > Dim conn As New SqlConnection("Server=apw-db;" & _ > >> > "DataBase=APW-System; Integrated Security=SSPI") > >> > Dim sqlstr As String = "SELECT * FROM sysName" > >> > Dim da As SqlDataAdapter > >> > Dim ds As New DataSet > >> > da = New SqlDataAdapter(sqlstr, conn) > >> > da.Fill(ds) > >> > Dim dt As DataTable = ds.Tables(0) > >> > > >> > MsgBox(dt.Rows.Item("sysName")) 'trying to show what is in field > >> > > >> > End Sub > >> > End Class > >> > >> > >> > > > Andrew,
>I found one of the problems there was no (0) after Rows in my code, but now I thought that I showed you that above. In what row is the exception error?.> when I execute I get the Exception error: > >> Cstr(ds.Tables(0).Rows(0).Item("sysName")) >> ds.Tables(0).Rows(0).Item("sysName").ToString >> Ctype(ds.Tables(0).Rows(0).Item("sysName"),String) >> Cor Show quoteHide quote >> Most people including me use the ToString, >> >> I have typed it in the message, looking at the major points. >> >> I hope it will go now, again not tested just typed. >> >> Cor >> >> >> "Andrew" <And***@discussions.microsoft.com> schreef in bericht >> news:077901A1-9479-4278-8E3C-37DEC01C7990@microsoft.com... >> > when I put as you put I get an error : "System.data.datarow" cannot be >> > converted to string. >> > >> > when I put convert.tostring(ds.Tables(0).Rows.Item("sysName"))) >> > >> > I get a new message: >> > >> > system.nullfreferenceExecptoin: Object Reference not set to instaance >> > of >> > an >> > Object. >> > as windowsApplication1.form1.button1_click() app path >> > ADodb.net\windowsaplication1\form1.vb:line71 >> > >> > I have one row with information in this table and the field is a >> > nvarchar(max) with allow nulls checked. >> > >> > "Cor Ligthert [MVP]" wrote: >> > >> >> Andrew, >> >> >> >> Nothing wrong with in my idea, however I would do it in its simplest >> >> format >> >> in this way. >> >> >> >> > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As >> >> > System.EventArgs) Handles Button1.Click >> >> > >> >> > Dim conn As New SqlConnection("Server=apw-db;" & _ >> >> > "DataBase=APW-System; Integrated >> >> > Security=SSPI") >> >> > Dim sqlstr As String = "SELECT * FROM sysName" >> >> Dim da As new SqlDataAdapter(sqlstr, conn) >> >> > Dim ds As New DataSet >> >> Try >> >> > da.Fill(ds) >> >> MessageBox.Show(ds.Tables(0).Rows.Item("sysName")) 'trying >> >> to >> >> show >> >> what is in field >> >> Catch ex as Exception >> >> MessageBox.Show(ex.ToString) >> >> End Try >> >> > End Sub >> >> >> >> I hope this helps, >> >> >> >> Cor >> >> >> >> >> >> "Andrew" <And***@discussions.microsoft.com> schreef in bericht >> >> news:0355ADCB-BE94-4D60-882A-E5D9ABDACDCD@microsoft.com... >> >> >I am simple tryint to learn how to use the ADO.NET code. Can anybody >> >> >tell >> >> >me >> >> > if I am using it right or not? >> >> > >> >> > Imports System.Data.sqlclient >> >> > Imports System.Data >> >> > >> >> > Public Class Form1 >> >> > >> >> > Inherits System.Windows.Forms.Form >> >> > >> >> > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As >> >> > System.EventArgs) Handles Button1.Click >> >> > >> >> > Dim conn As New SqlConnection("Server=apw-db;" & _ >> >> > "DataBase=APW-System; Integrated >> >> > Security=SSPI") >> >> > Dim sqlstr As String = "SELECT * FROM sysName" >> >> > Dim da As SqlDataAdapter >> >> > Dim ds As New DataSet >> >> > da = New SqlDataAdapter(sqlstr, conn) >> >> > da.Fill(ds) >> >> > Dim dt As DataTable = ds.Tables(0) >> >> > >> >> > MsgBox(dt.Rows.Item("sysName")) 'trying to show what is in >> >> > field >> >> > >> >> > End Sub >> >> > End Class >> >> >> >> >> >> >> >> >> I had make a mistake and mistyped what you had. but the error is coming from
row 71 on my app, the same row were I have the da.fill(ds). Show quoteHide quote "Cor Ligthert [MVP]" wrote: > Andrew, > > >I found one of the problems there was no (0) after Rows in my code, but now > > when I execute I get the Exception error: > > > >> Cstr(ds.Tables(0).Rows(0).Item("sysName")) > >> ds.Tables(0).Rows(0).Item("sysName").ToString > >> Ctype(ds.Tables(0).Rows(0).Item("sysName"),String) > >> > > I thought that I showed you that above. In what row is the exception error?. > > Cor > > >> Most people including me use the ToString, > >> > >> I have typed it in the message, looking at the major points. > >> > >> I hope it will go now, again not tested just typed. > >> > >> Cor > >> > >> > >> "Andrew" <And***@discussions.microsoft.com> schreef in bericht > >> news:077901A1-9479-4278-8E3C-37DEC01C7990@microsoft.com... > >> > when I put as you put I get an error : "System.data.datarow" cannot be > >> > converted to string. > >> > > >> > when I put convert.tostring(ds.Tables(0).Rows.Item("sysName"))) > >> > > >> > I get a new message: > >> > > >> > system.nullfreferenceExecptoin: Object Reference not set to instaance > >> > of > >> > an > >> > Object. > >> > as windowsApplication1.form1.button1_click() app path > >> > ADodb.net\windowsaplication1\form1.vb:line71 > >> > > >> > I have one row with information in this table and the field is a > >> > nvarchar(max) with allow nulls checked. > >> > > >> > "Cor Ligthert [MVP]" wrote: > >> > > >> >> Andrew, > >> >> > >> >> Nothing wrong with in my idea, however I would do it in its simplest > >> >> format > >> >> in this way. > >> >> > >> >> > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As > >> >> > System.EventArgs) Handles Button1.Click > >> >> > > >> >> > Dim conn As New SqlConnection("Server=apw-db;" & _ > >> >> > "DataBase=APW-System; Integrated > >> >> > Security=SSPI") > >> >> > Dim sqlstr As String = "SELECT * FROM sysName" > >> >> Dim da As new SqlDataAdapter(sqlstr, conn) > >> >> > Dim ds As New DataSet > >> >> Try > >> >> > da.Fill(ds) > >> >> MessageBox.Show(ds.Tables(0).Rows.Item("sysName")) 'trying > >> >> to > >> >> show > >> >> what is in field > >> >> Catch ex as Exception > >> >> MessageBox.Show(ex.ToString) > >> >> End Try > >> >> > End Sub > >> >> > >> >> I hope this helps, > >> >> > >> >> Cor > >> >> > >> >> > >> >> "Andrew" <And***@discussions.microsoft.com> schreef in bericht > >> >> news:0355ADCB-BE94-4D60-882A-E5D9ABDACDCD@microsoft.com... > >> >> >I am simple tryint to learn how to use the ADO.NET code. Can anybody > >> >> >tell > >> >> >me > >> >> > if I am using it right or not? > >> >> > > >> >> > Imports System.Data.sqlclient > >> >> > Imports System.Data > >> >> > > >> >> > Public Class Form1 > >> >> > > >> >> > Inherits System.Windows.Forms.Form > >> >> > > >> >> > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As > >> >> > System.EventArgs) Handles Button1.Click > >> >> > > >> >> > Dim conn As New SqlConnection("Server=apw-db;" & _ > >> >> > "DataBase=APW-System; Integrated > >> >> > Security=SSPI") > >> >> > Dim sqlstr As String = "SELECT * FROM sysName" > >> >> > Dim da As SqlDataAdapter > >> >> > Dim ds As New DataSet > >> >> > da = New SqlDataAdapter(sqlstr, conn) > >> >> > da.Fill(ds) > >> >> > Dim dt As DataTable = ds.Tables(0) > >> >> > > >> >> > MsgBox(dt.Rows.Item("sysName")) 'trying to show what is in > >> >> > field > >> >> > > >> >> > End Sub > >> >> > End Class > >> >> > >> >> > >> >> > >> > >> > >> > > > I think the error is coming from the:
da.fill(ds) ' function Show quoteHide quote "Cor Ligthert [MVP]" wrote: > Andrew, > > Sorry, this can be > Cstr(ds.Tables(0).Rows(0).Item("sysName")) > ds.Tables(0).Rows(0).Item("sysName").ToString > Ctype(ds.Tables(0).Rows(0).Item("sysName"),String) > > Most people including me use the ToString, > > I have typed it in the message, looking at the major points. > > I hope it will go now, again not tested just typed. > > Cor > > > "Andrew" <And***@discussions.microsoft.com> schreef in bericht > news:077901A1-9479-4278-8E3C-37DEC01C7990@microsoft.com... > > when I put as you put I get an error : "System.data.datarow" cannot be > > converted to string. > > > > when I put convert.tostring(ds.Tables(0).Rows.Item("sysName"))) > > > > I get a new message: > > > > system.nullfreferenceExecptoin: Object Reference not set to instaance of > > an > > Object. > > as windowsApplication1.form1.button1_click() app path > > ADodb.net\windowsaplication1\form1.vb:line71 > > > > I have one row with information in this table and the field is a > > nvarchar(max) with allow nulls checked. > > > > "Cor Ligthert [MVP]" wrote: > > > >> Andrew, > >> > >> Nothing wrong with in my idea, however I would do it in its simplest > >> format > >> in this way. > >> > >> > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As > >> > System.EventArgs) Handles Button1.Click > >> > > >> > Dim conn As New SqlConnection("Server=apw-db;" & _ > >> > "DataBase=APW-System; Integrated Security=SSPI") > >> > Dim sqlstr As String = "SELECT * FROM sysName" > >> Dim da As new SqlDataAdapter(sqlstr, conn) > >> > Dim ds As New DataSet > >> Try > >> > da.Fill(ds) > >> MessageBox.Show(ds.Tables(0).Rows.Item("sysName")) 'trying to > >> show > >> what is in field > >> Catch ex as Exception > >> MessageBox.Show(ex.ToString) > >> End Try > >> > End Sub > >> > >> I hope this helps, > >> > >> Cor > >> > >> > >> "Andrew" <And***@discussions.microsoft.com> schreef in bericht > >> news:0355ADCB-BE94-4D60-882A-E5D9ABDACDCD@microsoft.com... > >> >I am simple tryint to learn how to use the ADO.NET code. Can anybody > >> >tell > >> >me > >> > if I am using it right or not? > >> > > >> > Imports System.Data.sqlclient > >> > Imports System.Data > >> > > >> > Public Class Form1 > >> > > >> > Inherits System.Windows.Forms.Form > >> > > >> > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As > >> > System.EventArgs) Handles Button1.Click > >> > > >> > Dim conn As New SqlConnection("Server=apw-db;" & _ > >> > "DataBase=APW-System; Integrated Security=SSPI") > >> > Dim sqlstr As String = "SELECT * FROM sysName" > >> > Dim da As SqlDataAdapter > >> > Dim ds As New DataSet > >> > da = New SqlDataAdapter(sqlstr, conn) > >> > da.Fill(ds) > >> > Dim dt As DataTable = ds.Tables(0) > >> > > >> > MsgBox(dt.Rows.Item("sysName")) 'trying to show what is in field > >> > > >> > End Sub > >> > End Class > >> > >> > >> > > > Can you show your complete new code again,
Cor Show quoteHide quote "Andrew" <And***@discussions.microsoft.com> schreef in bericht news:B317D639-6D4B-4562-A4F5-4DB895EC9AED@microsoft.com... >I think the error is coming from the: > > da.fill(ds) ' function > > > > > > "Cor Ligthert [MVP]" wrote: > >> Andrew, >> >> Sorry, this can be >> Cstr(ds.Tables(0).Rows(0).Item("sysName")) >> ds.Tables(0).Rows(0).Item("sysName").ToString >> Ctype(ds.Tables(0).Rows(0).Item("sysName"),String) >> >> Most people including me use the ToString, >> >> I have typed it in the message, looking at the major points. >> >> I hope it will go now, again not tested just typed. >> >> Cor >> >> >> "Andrew" <And***@discussions.microsoft.com> schreef in bericht >> news:077901A1-9479-4278-8E3C-37DEC01C7990@microsoft.com... >> > when I put as you put I get an error : "System.data.datarow" cannot be >> > converted to string. >> > >> > when I put convert.tostring(ds.Tables(0).Rows.Item("sysName"))) >> > >> > I get a new message: >> > >> > system.nullfreferenceExecptoin: Object Reference not set to instaance >> > of >> > an >> > Object. >> > as windowsApplication1.form1.button1_click() app path >> > ADodb.net\windowsaplication1\form1.vb:line71 >> > >> > I have one row with information in this table and the field is a >> > nvarchar(max) with allow nulls checked. >> > >> > "Cor Ligthert [MVP]" wrote: >> > >> >> Andrew, >> >> >> >> Nothing wrong with in my idea, however I would do it in its simplest >> >> format >> >> in this way. >> >> >> >> > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As >> >> > System.EventArgs) Handles Button1.Click >> >> > >> >> > Dim conn As New SqlConnection("Server=apw-db;" & _ >> >> > "DataBase=APW-System; Integrated >> >> > Security=SSPI") >> >> > Dim sqlstr As String = "SELECT * FROM sysName" >> >> Dim da As new SqlDataAdapter(sqlstr, conn) >> >> > Dim ds As New DataSet >> >> Try >> >> > da.Fill(ds) >> >> MessageBox.Show(ds.Tables(0).Rows.Item("sysName")) 'trying >> >> to >> >> show >> >> what is in field >> >> Catch ex as Exception >> >> MessageBox.Show(ex.ToString) >> >> End Try >> >> > End Sub >> >> >> >> I hope this helps, >> >> >> >> Cor >> >> >> >> >> >> "Andrew" <And***@discussions.microsoft.com> schreef in bericht >> >> news:0355ADCB-BE94-4D60-882A-E5D9ABDACDCD@microsoft.com... >> >> >I am simple tryint to learn how to use the ADO.NET code. Can anybody >> >> >tell >> >> >me >> >> > if I am using it right or not? >> >> > >> >> > Imports System.Data.sqlclient >> >> > Imports System.Data >> >> > >> >> > Public Class Form1 >> >> > >> >> > Inherits System.Windows.Forms.Form >> >> > >> >> > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As >> >> > System.EventArgs) Handles Button1.Click >> >> > >> >> > Dim conn As New SqlConnection("Server=apw-db;" & _ >> >> > "DataBase=APW-System; Integrated >> >> > Security=SSPI") >> >> > Dim sqlstr As String = "SELECT * FROM sysName" >> >> > Dim da As SqlDataAdapter >> >> > Dim ds As New DataSet >> >> > da = New SqlDataAdapter(sqlstr, conn) >> >> > da.Fill(ds) >> >> > Dim dt As DataTable = ds.Tables(0) >> >> > >> >> > MsgBox(dt.Rows.Item("sysName")) 'trying to show what is in >> >> > field >> >> > >> >> > End Sub >> >> > End Class >> >> >> >> >> >> >> >> >> here is the new code:
Imports System.Data.sqlclient Imports System.Data Public Class Form1 Inherits System.Windows.Forms.Form Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim conn As New SqlConnection("Server=apw-db;" & _ "DataBase=APW-System; Integrated Security=SSPI") Dim sqlstr As String = "SELECT * FROM sysMaster WHERE sysName='IT_1'" Dim da As SqlDataAdapter Dim ds As New DataSet Try da.Fill(ds) MessageBox.Show(ds.Tables(0).Rows(0).Item("sysName").ToString) 'trying to show what is in field Catch ex As Exception MessageBox.Show(ex.ToString) End Try End Sub End Class Show quoteHide quote "Cor Ligthert [MVP]" wrote: > > Can you show your complete new code again, > > Cor > > > "Andrew" <And***@discussions.microsoft.com> schreef in bericht > news:B317D639-6D4B-4562-A4F5-4DB895EC9AED@microsoft.com... > >I think the error is coming from the: > > > > da.fill(ds) ' function > > > > > > > > > > > > "Cor Ligthert [MVP]" wrote: > > > >> Andrew, > >> > >> Sorry, this can be > >> Cstr(ds.Tables(0).Rows(0).Item("sysName")) > >> ds.Tables(0).Rows(0).Item("sysName").ToString > >> Ctype(ds.Tables(0).Rows(0).Item("sysName"),String) > >> > >> Most people including me use the ToString, > >> > >> I have typed it in the message, looking at the major points. > >> > >> I hope it will go now, again not tested just typed. > >> > >> Cor > >> > >> > >> "Andrew" <And***@discussions.microsoft.com> schreef in bericht > >> news:077901A1-9479-4278-8E3C-37DEC01C7990@microsoft.com... > >> > when I put as you put I get an error : "System.data.datarow" cannot be > >> > converted to string. > >> > > >> > when I put convert.tostring(ds.Tables(0).Rows.Item("sysName"))) > >> > > >> > I get a new message: > >> > > >> > system.nullfreferenceExecptoin: Object Reference not set to instaance > >> > of > >> > an > >> > Object. > >> > as windowsApplication1.form1.button1_click() app path > >> > ADodb.net\windowsaplication1\form1.vb:line71 > >> > > >> > I have one row with information in this table and the field is a > >> > nvarchar(max) with allow nulls checked. > >> > > >> > "Cor Ligthert [MVP]" wrote: > >> > > >> >> Andrew, > >> >> > >> >> Nothing wrong with in my idea, however I would do it in its simplest > >> >> format > >> >> in this way. > >> >> > >> >> > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As > >> >> > System.EventArgs) Handles Button1.Click > >> >> > > >> >> > Dim conn As New SqlConnection("Server=apw-db;" & _ > >> >> > "DataBase=APW-System; Integrated > >> >> > Security=SSPI") > >> >> > Dim sqlstr As String = "SELECT * FROM sysName" > >> >> Dim da As new SqlDataAdapter(sqlstr, conn) > >> >> > Dim ds As New DataSet > >> >> Try > >> >> > da.Fill(ds) > >> >> MessageBox.Show(ds.Tables(0).Rows.Item("sysName")) 'trying > >> >> to > >> >> show > >> >> what is in field > >> >> Catch ex as Exception > >> >> MessageBox.Show(ex.ToString) > >> >> End Try > >> >> > End Sub > >> >> > >> >> I hope this helps, > >> >> > >> >> Cor > >> >> > >> >> > >> >> "Andrew" <And***@discussions.microsoft.com> schreef in bericht > >> >> news:0355ADCB-BE94-4D60-882A-E5D9ABDACDCD@microsoft.com... > >> >> >I am simple tryint to learn how to use the ADO.NET code. Can anybody > >> >> >tell > >> >> >me > >> >> > if I am using it right or not? > >> >> > > >> >> > Imports System.Data.sqlclient > >> >> > Imports System.Data > >> >> > > >> >> > Public Class Form1 > >> >> > > >> >> > Inherits System.Windows.Forms.Form > >> >> > > >> >> > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As > >> >> > System.EventArgs) Handles Button1.Click > >> >> > > >> >> > Dim conn As New SqlConnection("Server=apw-db;" & _ > >> >> > "DataBase=APW-System; Integrated > >> >> > Security=SSPI") > >> >> > Dim sqlstr As String = "SELECT * FROM sysName" > >> >> > Dim da As SqlDataAdapter > >> >> > Dim ds As New DataSet > >> >> > da = New SqlDataAdapter(sqlstr, conn) > >> >> > da.Fill(ds) > >> >> > Dim dt As DataTable = ds.Tables(0) > >> >> > > >> >> > MsgBox(dt.Rows.Item("sysName")) 'trying to show what is in > >> >> > field > >> >> > > >> >> > End Sub > >> >> > End Class > >> >> > >> >> > >> >> > >> > >> > >> > > > Instantiate da.
Show quoteHide quote "Andrew" <And***@discussions.microsoft.com> wrote in message news:0AD0BAC4-522C-44D3-BCDE-63F08220BE02@microsoft.com... > here is the new code: > > > Imports System.Data.sqlclient > Imports System.Data > > Public Class Form1 > > Inherits System.Windows.Forms.Form > > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As > System.EventArgs) Handles Button1.Click > > Dim conn As New SqlConnection("Server=apw-db;" & _ > "DataBase=APW-System; Integrated Security=SSPI") > Dim sqlstr As String = "SELECT * FROM sysMaster WHERE > sysName='IT_1'" > Dim da As SqlDataAdapter > Dim ds As New DataSet > > Try > da.Fill(ds) > > MessageBox.Show(ds.Tables(0).Rows(0).Item("sysName").ToString) > 'trying to show what is in field > Catch ex As Exception > MessageBox.Show(ex.ToString) > > End Try > > End Sub > End Class > > > > "Cor Ligthert [MVP]" wrote: > >> >> Can you show your complete new code again, >> >> Cor >> >> >> "Andrew" <And***@discussions.microsoft.com> schreef in bericht >> news:B317D639-6D4B-4562-A4F5-4DB895EC9AED@microsoft.com... >> >I think the error is coming from the: >> > >> > da.fill(ds) ' function >> > >> > >> > >> > >> > >> > "Cor Ligthert [MVP]" wrote: >> > >> >> Andrew, >> >> >> >> Sorry, this can be >> >> Cstr(ds.Tables(0).Rows(0).Item("sysName")) >> >> ds.Tables(0).Rows(0).Item("sysName").ToString >> >> Ctype(ds.Tables(0).Rows(0).Item("sysName"),String) >> >> >> >> Most people including me use the ToString, >> >> >> >> I have typed it in the message, looking at the major points. >> >> >> >> I hope it will go now, again not tested just typed. >> >> >> >> Cor >> >> >> >> >> >> "Andrew" <And***@discussions.microsoft.com> schreef in bericht >> >> news:077901A1-9479-4278-8E3C-37DEC01C7990@microsoft.com... >> >> > when I put as you put I get an error : "System.data.datarow" cannot >> >> > be >> >> > converted to string. >> >> > >> >> > when I put convert.tostring(ds.Tables(0).Rows.Item("sysName"))) >> >> > >> >> > I get a new message: >> >> > >> >> > system.nullfreferenceExecptoin: Object Reference not set to >> >> > instaance >> >> > of >> >> > an >> >> > Object. >> >> > as windowsApplication1.form1.button1_click() app path >> >> > ADodb.net\windowsaplication1\form1.vb:line71 >> >> > >> >> > I have one row with information in this table and the field is a >> >> > nvarchar(max) with allow nulls checked. >> >> > >> >> > "Cor Ligthert [MVP]" wrote: >> >> > >> >> >> Andrew, >> >> >> >> >> >> Nothing wrong with in my idea, however I would do it in its >> >> >> simplest >> >> >> format >> >> >> in this way. >> >> >> >> >> >> > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e >> >> >> > As >> >> >> > System.EventArgs) Handles Button1.Click >> >> >> > >> >> >> > Dim conn As New SqlConnection("Server=apw-db;" & _ >> >> >> > "DataBase=APW-System; Integrated >> >> >> > Security=SSPI") >> >> >> > Dim sqlstr As String = "SELECT * FROM sysName" >> >> >> Dim da As new SqlDataAdapter(sqlstr, conn) >> >> >> > Dim ds As New DataSet >> >> >> Try >> >> >> > da.Fill(ds) >> >> >> MessageBox.Show(ds.Tables(0).Rows.Item("sysName")) >> >> >> 'trying >> >> >> to >> >> >> show >> >> >> what is in field >> >> >> Catch ex as Exception >> >> >> MessageBox.Show(ex.ToString) >> >> >> End Try >> >> >> > End Sub >> >> >> >> >> >> I hope this helps, >> >> >> >> >> >> Cor >> >> >> >> >> >> >> >> >> "Andrew" <And***@discussions.microsoft.com> schreef in bericht >> >> >> news:0355ADCB-BE94-4D60-882A-E5D9ABDACDCD@microsoft.com... >> >> >> >I am simple tryint to learn how to use the ADO.NET code. Can >> >> >> >anybody >> >> >> >tell >> >> >> >me >> >> >> > if I am using it right or not? >> >> >> > >> >> >> > Imports System.Data.sqlclient >> >> >> > Imports System.Data >> >> >> > >> >> >> > Public Class Form1 >> >> >> > >> >> >> > Inherits System.Windows.Forms.Form >> >> >> > >> >> >> > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e >> >> >> > As >> >> >> > System.EventArgs) Handles Button1.Click >> >> >> > >> >> >> > Dim conn As New SqlConnection("Server=apw-db;" & _ >> >> >> > "DataBase=APW-System; Integrated >> >> >> > Security=SSPI") >> >> >> > Dim sqlstr As String = "SELECT * FROM sysName" >> >> >> > Dim da As SqlDataAdapter >> >> >> > Dim ds As New DataSet >> >> >> > da = New SqlDataAdapter(sqlstr, conn) >> >> >> > da.Fill(ds) >> >> >> > Dim dt As DataTable = ds.Tables(0) >> >> >> > >> >> >> > MsgBox(dt.Rows.Item("sysName")) 'trying to show what is in >> >> >> > field >> >> >> > >> >> >> > End Sub >> >> >> > End Class >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> how would I do that in .net?
Show quoteHide quote "Stephany Young" wrote: > Instantiate da. > > > "Andrew" <And***@discussions.microsoft.com> wrote in message > news:0AD0BAC4-522C-44D3-BCDE-63F08220BE02@microsoft.com... > > here is the new code: > > > > > > Imports System.Data.sqlclient > > Imports System.Data > > > > Public Class Form1 > > > > Inherits System.Windows.Forms.Form > > > > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As > > System.EventArgs) Handles Button1.Click > > > > Dim conn As New SqlConnection("Server=apw-db;" & _ > > "DataBase=APW-System; Integrated Security=SSPI") > > Dim sqlstr As String = "SELECT * FROM sysMaster WHERE > > sysName='IT_1'" > > Dim da As SqlDataAdapter > > Dim ds As New DataSet > > > > Try > > da.Fill(ds) > > > > MessageBox.Show(ds.Tables(0).Rows(0).Item("sysName").ToString) > > 'trying to show what is in field > > Catch ex As Exception > > MessageBox.Show(ex.ToString) > > > > End Try > > > > End Sub > > End Class > > > > > > > > "Cor Ligthert [MVP]" wrote: > > > >> > >> Can you show your complete new code again, > >> > >> Cor > >> > >> > >> "Andrew" <And***@discussions.microsoft.com> schreef in bericht > >> news:B317D639-6D4B-4562-A4F5-4DB895EC9AED@microsoft.com... > >> >I think the error is coming from the: > >> > > >> > da.fill(ds) ' function > >> > > >> > > >> > > >> > > >> > > >> > "Cor Ligthert [MVP]" wrote: > >> > > >> >> Andrew, > >> >> > >> >> Sorry, this can be > >> >> Cstr(ds.Tables(0).Rows(0).Item("sysName")) > >> >> ds.Tables(0).Rows(0).Item("sysName").ToString > >> >> Ctype(ds.Tables(0).Rows(0).Item("sysName"),String) > >> >> > >> >> Most people including me use the ToString, > >> >> > >> >> I have typed it in the message, looking at the major points. > >> >> > >> >> I hope it will go now, again not tested just typed. > >> >> > >> >> Cor > >> >> > >> >> > >> >> "Andrew" <And***@discussions.microsoft.com> schreef in bericht > >> >> news:077901A1-9479-4278-8E3C-37DEC01C7990@microsoft.com... > >> >> > when I put as you put I get an error : "System.data.datarow" cannot > >> >> > be > >> >> > converted to string. > >> >> > > >> >> > when I put convert.tostring(ds.Tables(0).Rows.Item("sysName"))) > >> >> > > >> >> > I get a new message: > >> >> > > >> >> > system.nullfreferenceExecptoin: Object Reference not set to > >> >> > instaance > >> >> > of > >> >> > an > >> >> > Object. > >> >> > as windowsApplication1.form1.button1_click() app path > >> >> > ADodb.net\windowsaplication1\form1.vb:line71 > >> >> > > >> >> > I have one row with information in this table and the field is a > >> >> > nvarchar(max) with allow nulls checked. > >> >> > > >> >> > "Cor Ligthert [MVP]" wrote: > >> >> > > >> >> >> Andrew, > >> >> >> > >> >> >> Nothing wrong with in my idea, however I would do it in its > >> >> >> simplest > >> >> >> format > >> >> >> in this way. > >> >> >> > >> >> >> > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e > >> >> >> > As > >> >> >> > System.EventArgs) Handles Button1.Click > >> >> >> > > >> >> >> > Dim conn As New SqlConnection("Server=apw-db;" & _ > >> >> >> > "DataBase=APW-System; Integrated > >> >> >> > Security=SSPI") > >> >> >> > Dim sqlstr As String = "SELECT * FROM sysName" > >> >> >> Dim da As new SqlDataAdapter(sqlstr, conn) > >> >> >> > Dim ds As New DataSet > >> >> >> Try > >> >> >> > da.Fill(ds) > >> >> >> MessageBox.Show(ds.Tables(0).Rows.Item("sysName")) > >> >> >> 'trying > >> >> >> to > >> >> >> show > >> >> >> what is in field > >> >> >> Catch ex as Exception > >> >> >> MessageBox.Show(ex.ToString) > >> >> >> End Try > >> >> >> > End Sub > >> >> >> > >> >> >> I hope this helps, > >> >> >> > >> >> >> Cor > >> >> >> > >> >> >> > >> >> >> "Andrew" <And***@discussions.microsoft.com> schreef in bericht > >> >> >> news:0355ADCB-BE94-4D60-882A-E5D9ABDACDCD@microsoft.com... > >> >> >> >I am simple tryint to learn how to use the ADO.NET code. Can > >> >> >> >anybody > >> >> >> >tell > >> >> >> >me > >> >> >> > if I am using it right or not? > >> >> >> > > >> >> >> > Imports System.Data.sqlclient > >> >> >> > Imports System.Data > >> >> >> > > >> >> >> > Public Class Form1 > >> >> >> > > >> >> >> > Inherits System.Windows.Forms.Form > >> >> >> > > >> >> >> > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e > >> >> >> > As > >> >> >> > System.EventArgs) Handles Button1.Click > >> >> >> > > >> >> >> > Dim conn As New SqlConnection("Server=apw-db;" & _ > >> >> >> > "DataBase=APW-System; Integrated > >> >> >> > Security=SSPI") > >> >> >> > Dim sqlstr As String = "SELECT * FROM sysName" > >> >> >> > Dim da As SqlDataAdapter > >> >> >> > Dim ds As New DataSet > >> >> >> > da = New SqlDataAdapter(sqlstr, conn) > >> >> >> > da.Fill(ds) > >> >> >> > Dim dt As DataTable = ds.Tables(0) > >> >> >> > > >> >> >> > MsgBox(dt.Rows.Item("sysName")) 'trying to show what is in > >> >> >> > field > >> >> >> > > >> >> >> > End Sub > >> >> >> > End Class > >> >> >> > >> >> >> > >> >> >> > >> >> > >> >> > >> >> > >> > >> > >> > > > You did it quite successfully in your original post.
Show quoteHide quote "Andrew" <And***@discussions.microsoft.com> wrote in message news:2E575AF0-4172-4920-A0F9-2F744BB19CA4@microsoft.com... > how would I do that in .net? > > "Stephany Young" wrote: > >> Instantiate da. >> >> >> "Andrew" <And***@discussions.microsoft.com> wrote in message >> news:0AD0BAC4-522C-44D3-BCDE-63F08220BE02@microsoft.com... >> > here is the new code: >> > >> > >> > Imports System.Data.sqlclient >> > Imports System.Data >> > >> > Public Class Form1 >> > >> > Inherits System.Windows.Forms.Form >> > >> > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As >> > System.EventArgs) Handles Button1.Click >> > >> > Dim conn As New SqlConnection("Server=apw-db;" & _ >> > "DataBase=APW-System; Integrated Security=SSPI") >> > Dim sqlstr As String = "SELECT * FROM sysMaster WHERE >> > sysName='IT_1'" >> > Dim da As SqlDataAdapter >> > Dim ds As New DataSet >> > >> > Try >> > da.Fill(ds) >> > >> > >> > MessageBox.Show(ds.Tables(0).Rows(0).Item("sysName").ToString) >> > 'trying to show what is in field >> > Catch ex As Exception >> > MessageBox.Show(ex.ToString) >> > >> > End Try >> > >> > End Sub >> > End Class >> > >> > >> > >> > "Cor Ligthert [MVP]" wrote: >> > >> >> >> >> Can you show your complete new code again, >> >> >> >> Cor >> >> >> >> >> >> "Andrew" <And***@discussions.microsoft.com> schreef in bericht >> >> news:B317D639-6D4B-4562-A4F5-4DB895EC9AED@microsoft.com... >> >> >I think the error is coming from the: >> >> > >> >> > da.fill(ds) ' function >> >> > >> >> > >> >> > >> >> > >> >> > >> >> > "Cor Ligthert [MVP]" wrote: >> >> > >> >> >> Andrew, >> >> >> >> >> >> Sorry, this can be >> >> >> Cstr(ds.Tables(0).Rows(0).Item("sysName")) >> >> >> ds.Tables(0).Rows(0).Item("sysName").ToString >> >> >> Ctype(ds.Tables(0).Rows(0).Item("sysName"),String) >> >> >> >> >> >> Most people including me use the ToString, >> >> >> >> >> >> I have typed it in the message, looking at the major points. >> >> >> >> >> >> I hope it will go now, again not tested just typed. >> >> >> >> >> >> Cor >> >> >> >> >> >> >> >> >> "Andrew" <And***@discussions.microsoft.com> schreef in bericht >> >> >> news:077901A1-9479-4278-8E3C-37DEC01C7990@microsoft.com... >> >> >> > when I put as you put I get an error : "System.data.datarow" >> >> >> > cannot >> >> >> > be >> >> >> > converted to string. >> >> >> > >> >> >> > when I put convert.tostring(ds.Tables(0).Rows.Item("sysName"))) >> >> >> > >> >> >> > I get a new message: >> >> >> > >> >> >> > system.nullfreferenceExecptoin: Object Reference not set to >> >> >> > instaance >> >> >> > of >> >> >> > an >> >> >> > Object. >> >> >> > as windowsApplication1.form1.button1_click() app path >> >> >> > ADodb.net\windowsaplication1\form1.vb:line71 >> >> >> > >> >> >> > I have one row with information in this table and the field is a >> >> >> > nvarchar(max) with allow nulls checked. >> >> >> > >> >> >> > "Cor Ligthert [MVP]" wrote: >> >> >> > >> >> >> >> Andrew, >> >> >> >> >> >> >> >> Nothing wrong with in my idea, however I would do it in its >> >> >> >> simplest >> >> >> >> format >> >> >> >> in this way. >> >> >> >> >> >> >> >> > Private Sub Button1_Click(ByVal sender As System.Object, ByVal >> >> >> >> > e >> >> >> >> > As >> >> >> >> > System.EventArgs) Handles Button1.Click >> >> >> >> > >> >> >> >> > Dim conn As New SqlConnection("Server=apw-db;" & _ >> >> >> >> > "DataBase=APW-System; Integrated >> >> >> >> > Security=SSPI") >> >> >> >> > Dim sqlstr As String = "SELECT * FROM sysName" >> >> >> >> Dim da As new SqlDataAdapter(sqlstr, conn) >> >> >> >> > Dim ds As New DataSet >> >> >> >> Try >> >> >> >> > da.Fill(ds) >> >> >> >> MessageBox.Show(ds.Tables(0).Rows.Item("sysName")) >> >> >> >> 'trying >> >> >> >> to >> >> >> >> show >> >> >> >> what is in field >> >> >> >> Catch ex as Exception >> >> >> >> MessageBox.Show(ex.ToString) >> >> >> >> End Try >> >> >> >> > End Sub >> >> >> >> >> >> >> >> I hope this helps, >> >> >> >> >> >> >> >> Cor >> >> >> >> >> >> >> >> >> >> >> >> "Andrew" <And***@discussions.microsoft.com> schreef in bericht >> >> >> >> news:0355ADCB-BE94-4D60-882A-E5D9ABDACDCD@microsoft.com... >> >> >> >> >I am simple tryint to learn how to use the ADO.NET code. Can >> >> >> >> >anybody >> >> >> >> >tell >> >> >> >> >me >> >> >> >> > if I am using it right or not? >> >> >> >> > >> >> >> >> > Imports System.Data.sqlclient >> >> >> >> > Imports System.Data >> >> >> >> > >> >> >> >> > Public Class Form1 >> >> >> >> > >> >> >> >> > Inherits System.Windows.Forms.Form >> >> >> >> > >> >> >> >> > Private Sub Button1_Click(ByVal sender As System.Object, ByVal >> >> >> >> > e >> >> >> >> > As >> >> >> >> > System.EventArgs) Handles Button1.Click >> >> >> >> > >> >> >> >> > Dim conn As New SqlConnection("Server=apw-db;" & _ >> >> >> >> > "DataBase=APW-System; Integrated >> >> >> >> > Security=SSPI") >> >> >> >> > Dim sqlstr As String = "SELECT * FROM sysName" >> >> >> >> > Dim da As SqlDataAdapter >> >> >> >> > Dim ds As New DataSet >> >> >> >> > da = New SqlDataAdapter(sqlstr, conn) >> >> >> >> > da.Fill(ds) >> >> >> >> > Dim dt As DataTable = ds.Tables(0) >> >> >> >> > >> >> >> >> > MsgBox(dt.Rows.Item("sysName")) 'trying to show what is >> >> >> >> > in >> >> >> >> > field >> >> >> >> > >> >> >> >> > End Sub >> >> >> >> > End Class >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> Thanks for pointing that out, I was having a brain fart. At the time I got
this reply back I was noticing that there was no command execution for the sql string. Not I am getting a reply back from the server, how ever I am not use to logging in with windows authentication. Is the provider string done the same way as in the previous version of adodb. This is my string with the previous version "Provider=SQLOLEDB.1;User ID=sa;password=" & sPassword & ";Initial Catalog=" & sDBName & ";Data Source = " & sServer & ";Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096" Is it the same in adodb.net or different? and if I was to update a database through a sql string with this code, Do I do the same type of execution with the update sql string? example of old: cmd.ActiveConnection = conn cmd.CommandText = "INSERT INTO driveMaster (driveID,sysID,evenID,driveDate,driveLET,driveTtl,driveFree)" & _ "VALUES (NEWID(), " & uID & ", 'ID3333', current_timestamp, '" & sD & "', '" & iTtl & "', '" & iFree & "')" cmd.CommandType = ADODB.CommandTypeEnum.adCmdText rs = cmd.Execute Show quoteHide quote "Stephany Young" wrote: > You did it quite successfully in your original post. > > > "Andrew" <And***@discussions.microsoft.com> wrote in message > news:2E575AF0-4172-4920-A0F9-2F744BB19CA4@microsoft.com... > > how would I do that in .net? > > > > "Stephany Young" wrote: > > > >> Instantiate da. > >> > >> > >> "Andrew" <And***@discussions.microsoft.com> wrote in message > >> news:0AD0BAC4-522C-44D3-BCDE-63F08220BE02@microsoft.com... > >> > here is the new code: > >> > > >> > > >> > Imports System.Data.sqlclient > >> > Imports System.Data > >> > > >> > Public Class Form1 > >> > > >> > Inherits System.Windows.Forms.Form > >> > > >> > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As > >> > System.EventArgs) Handles Button1.Click > >> > > >> > Dim conn As New SqlConnection("Server=apw-db;" & _ > >> > "DataBase=APW-System; Integrated Security=SSPI") > >> > Dim sqlstr As String = "SELECT * FROM sysMaster WHERE > >> > sysName='IT_1'" > >> > Dim da As SqlDataAdapter > >> > Dim ds As New DataSet > >> > > >> > Try > >> > da.Fill(ds) > >> > > >> > > >> > MessageBox.Show(ds.Tables(0).Rows(0).Item("sysName").ToString) > >> > 'trying to show what is in field > >> > Catch ex As Exception > >> > MessageBox.Show(ex.ToString) > >> > > >> > End Try > >> > > >> > End Sub > >> > End Class > >> > > >> > > >> > > >> > "Cor Ligthert [MVP]" wrote: > >> > > >> >> > >> >> Can you show your complete new code again, > >> >> > >> >> Cor > >> >> > >> >> > >> >> "Andrew" <And***@discussions.microsoft.com> schreef in bericht > >> >> news:B317D639-6D4B-4562-A4F5-4DB895EC9AED@microsoft.com... > >> >> >I think the error is coming from the: > >> >> > > >> >> > da.fill(ds) ' function > >> >> > > >> >> > > >> >> > > >> >> > > >> >> > > >> >> > "Cor Ligthert [MVP]" wrote: > >> >> > > >> >> >> Andrew, > >> >> >> > >> >> >> Sorry, this can be > >> >> >> Cstr(ds.Tables(0).Rows(0).Item("sysName")) > >> >> >> ds.Tables(0).Rows(0).Item("sysName").ToString > >> >> >> Ctype(ds.Tables(0).Rows(0).Item("sysName"),String) > >> >> >> > >> >> >> Most people including me use the ToString, > >> >> >> > >> >> >> I have typed it in the message, looking at the major points. > >> >> >> > >> >> >> I hope it will go now, again not tested just typed. > >> >> >> > >> >> >> Cor > >> >> >> > >> >> >> > >> >> >> "Andrew" <And***@discussions.microsoft.com> schreef in bericht > >> >> >> news:077901A1-9479-4278-8E3C-37DEC01C7990@microsoft.com... > >> >> >> > when I put as you put I get an error : "System.data.datarow" > >> >> >> > cannot > >> >> >> > be > >> >> >> > converted to string. > >> >> >> > > >> >> >> > when I put convert.tostring(ds.Tables(0).Rows.Item("sysName"))) > >> >> >> > > >> >> >> > I get a new message: > >> >> >> > > >> >> >> > system.nullfreferenceExecptoin: Object Reference not set to > >> >> >> > instaance > >> >> >> > of > >> >> >> > an > >> >> >> > Object. > >> >> >> > as windowsApplication1.form1.button1_click() app path > >> >> >> > ADodb.net\windowsaplication1\form1.vb:line71 > >> >> >> > > >> >> >> > I have one row with information in this table and the field is a > >> >> >> > nvarchar(max) with allow nulls checked. > >> >> >> > > >> >> >> > "Cor Ligthert [MVP]" wrote: > >> >> >> > > >> >> >> >> Andrew, > >> >> >> >> > >> >> >> >> Nothing wrong with in my idea, however I would do it in its > >> >> >> >> simplest > >> >> >> >> format > >> >> >> >> in this way. > >> >> >> >> > >> >> >> >> > Private Sub Button1_Click(ByVal sender As System.Object, ByVal > >> >> >> >> > e > >> >> >> >> > As > >> >> >> >> > System.EventArgs) Handles Button1.Click > >> >> >> >> > > >> >> >> >> > Dim conn As New SqlConnection("Server=apw-db;" & _ > >> >> >> >> > "DataBase=APW-System; Integrated > >> >> >> >> > Security=SSPI") > >> >> >> >> > Dim sqlstr As String = "SELECT * FROM sysName" > >> >> >> >> Dim da As new SqlDataAdapter(sqlstr, conn) > >> >> >> >> > Dim ds As New DataSet > >> >> >> >> Try > >> >> >> >> > da.Fill(ds) > >> >> >> >> MessageBox.Show(ds.Tables(0).Rows.Item("sysName")) > >> >> >> >> 'trying > >> >> >> >> to > >> >> >> >> show > >> >> >> >> what is in field > >> >> >> >> Catch ex as Exception > >> >> >> >> MessageBox.Show(ex.ToString) > >> >> >> >> End Try > >> >> >> >> > End Sub > >> >> >> >> > >> >> >> >> I hope this helps, > >> >> >> >> > >> >> >> >> Cor > >> >> >> >> > >> >> >> >> > >> >> >> >> "Andrew" <And***@discussions.microsoft.com> schreef in bericht > >> >> >> >> news:0355ADCB-BE94-4D60-882A-E5D9ABDACDCD@microsoft.com... > >> >> >> >> >I am simple tryint to learn how to use the ADO.NET code. Can > >> >> >> >> >anybody > >> >> >> >> >tell > >> >> >> >> >me > >> >> >> >> > if I am using it right or not? > >> >> >> >> > > >> >> >> >> > Imports System.Data.sqlclient > >> >> >> >> > Imports System.Data > >> >> >> >> > > >> >> >> >> > Public Class Form1 > >> >> >> >> > > >> >> >> >> > Inherits System.Windows.Forms.Form > >> >> >> >> > > >> >> >> >> > Private Sub Button1_Click(ByVal sender As System.Object, ByVal > >> >> >> >> > e > >> >> >> >> > As > >> >> >> >> > System.EventArgs) Handles Button1.Click > >> >> >> >> > > >> >> >> >> > Dim conn As New SqlConnection("Server=apw-db;" & _ > >> >> >> >> > "DataBase=APW-System; Integrated > >> >> >> >> > Security=SSPI") > >> >> >> >> > Dim sqlstr As String = "SELECT * FROM sysName" > >> >> >> >> > Dim da As SqlDataAdapter > >> >> >> >> > Dim ds As New DataSet > >> >> >> >> > da = New SqlDataAdapter(sqlstr, conn) > >> >> >> >> > da.Fill(ds) > >> >> >> >> > Dim dt As DataTable = ds.Tables(0) > >> >> >> >> > > >> >> >> >> > MsgBox(dt.Rows.Item("sysName")) 'trying to show what is > >> >> >> >> > in > >> >> >> >> > field > >> >> >> >> > > >> >> >> >> > End Sub > >> >> >> >> > End Class > >> >> >> >> > >> >> >> >> > >> >> >> >> > >> >> >> > >> >> >> > >> >> >> > >> >> > >> >> > >> >> > >> > >> > >> > > > When you are using the SqlClient objects, DO NOT include the Provider clause
in the connection string. If you are using SQl Server authentication then the minimum connection string is: Data Source=<server>;Initial Catalog=<database>;User ID=<username>;Password=<password> where the tokens (<server>, <database>, <username> and <password>) are replaced with your own values. The 'new' method for doing an insert is to instantiate a SqlCommand object and call it's ExecuteNONQuery method: Dim _con As New SqlConnection(_connectionstring) Dim _com As New SqlCommand(_insertsqlstring, _con) _com.Parameters.Add(_parametername, _parametertype).Value = _parametervalue ' Add all required parameters _con.Open() _com.ExceuteNonQuery() _con.Close() I suggest you study the documentation relating to the System.Data.SqlClient.SqlCommand class along with the documentation for other related classes. Show quoteHide quote "Andrew" <And***@discussions.microsoft.com> wrote in message news:AA56360C-730B-4E68-B907-5483C691D5CC@microsoft.com... > Thanks for pointing that out, I was having a brain fart. At the time I got > this reply back I was noticing that there was no command execution for the > sql string. Not I am getting a reply back from the server, how ever I am > not > use to logging in with windows authentication. > > Is the provider string done the same way as in the previous version of > adodb. This is my string with the previous version > > "Provider=SQLOLEDB.1;User ID=sa;password=" & sPassword & ";Initial > Catalog=" > & sDBName & ";Data Source = " & sServer & ";Use Procedure for > Prepare=1;Auto > Translate=True;Packet Size=4096" > > Is it the same in adodb.net or different? > > and if I was to update a database through a sql string with this code, Do > I > do the same type of execution with the update sql string? > > example of old: > > > cmd.ActiveConnection = conn > cmd.CommandText = "INSERT INTO driveMaster > (driveID,sysID,evenID,driveDate,driveLET,driveTtl,driveFree)" & _ > "VALUES (NEWID(), " & uID & ", 'ID3333', current_timestamp, > '" & sD & "', '" & iTtl & "', '" & iFree & "')" > cmd.CommandType = ADODB.CommandTypeEnum.adCmdText > rs = cmd.Execute > > > > > > > > "Stephany Young" wrote: > >> You did it quite successfully in your original post. >> >> >> "Andrew" <And***@discussions.microsoft.com> wrote in message >> news:2E575AF0-4172-4920-A0F9-2F744BB19CA4@microsoft.com... >> > how would I do that in .net? >> > >> > "Stephany Young" wrote: >> > >> >> Instantiate da. >> >> >> >> >> >> "Andrew" <And***@discussions.microsoft.com> wrote in message >> >> news:0AD0BAC4-522C-44D3-BCDE-63F08220BE02@microsoft.com... >> >> > here is the new code: >> >> > >> >> > >> >> > Imports System.Data.sqlclient >> >> > Imports System.Data >> >> > >> >> > Public Class Form1 >> >> > >> >> > Inherits System.Windows.Forms.Form >> >> > >> >> > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As >> >> > System.EventArgs) Handles Button1.Click >> >> > >> >> > Dim conn As New SqlConnection("Server=apw-db;" & _ >> >> > "DataBase=APW-System; Integrated >> >> > Security=SSPI") >> >> > Dim sqlstr As String = "SELECT * FROM sysMaster WHERE >> >> > sysName='IT_1'" >> >> > Dim da As SqlDataAdapter >> >> > Dim ds As New DataSet >> >> > >> >> > Try >> >> > da.Fill(ds) >> >> > >> >> > >> >> > MessageBox.Show(ds.Tables(0).Rows(0).Item("sysName").ToString) >> >> > 'trying to show what is in field >> >> > Catch ex As Exception >> >> > MessageBox.Show(ex.ToString) >> >> > >> >> > End Try >> >> > >> >> > End Sub >> >> > End Class >> >> > >> >> > >> >> > >> >> > "Cor Ligthert [MVP]" wrote: >> >> > >> >> >> >> >> >> Can you show your complete new code again, >> >> >> >> >> >> Cor >> >> >> >> >> >> >> >> >> "Andrew" <And***@discussions.microsoft.com> schreef in bericht >> >> >> news:B317D639-6D4B-4562-A4F5-4DB895EC9AED@microsoft.com... >> >> >> >I think the error is coming from the: >> >> >> > >> >> >> > da.fill(ds) ' function >> >> >> > >> >> >> > >> >> >> > >> >> >> > >> >> >> > >> >> >> > "Cor Ligthert [MVP]" wrote: >> >> >> > >> >> >> >> Andrew, >> >> >> >> >> >> >> >> Sorry, this can be >> >> >> >> Cstr(ds.Tables(0).Rows(0).Item("sysName")) >> >> >> >> ds.Tables(0).Rows(0).Item("sysName").ToString >> >> >> >> Ctype(ds.Tables(0).Rows(0).Item("sysName"),String) >> >> >> >> >> >> >> >> Most people including me use the ToString, >> >> >> >> >> >> >> >> I have typed it in the message, looking at the major points. >> >> >> >> >> >> >> >> I hope it will go now, again not tested just typed. >> >> >> >> >> >> >> >> Cor >> >> >> >> >> >> >> >> >> >> >> >> "Andrew" <And***@discussions.microsoft.com> schreef in bericht >> >> >> >> news:077901A1-9479-4278-8E3C-37DEC01C7990@microsoft.com... >> >> >> >> > when I put as you put I get an error : "System.data.datarow" >> >> >> >> > cannot >> >> >> >> > be >> >> >> >> > converted to string. >> >> >> >> > >> >> >> >> > when I put >> >> >> >> > convert.tostring(ds.Tables(0).Rows.Item("sysName"))) >> >> >> >> > >> >> >> >> > I get a new message: >> >> >> >> > >> >> >> >> > system.nullfreferenceExecptoin: Object Reference not set to >> >> >> >> > instaance >> >> >> >> > of >> >> >> >> > an >> >> >> >> > Object. >> >> >> >> > as windowsApplication1.form1.button1_click() app path >> >> >> >> > ADodb.net\windowsaplication1\form1.vb:line71 >> >> >> >> > >> >> >> >> > I have one row with information in this table and the field is >> >> >> >> > a >> >> >> >> > nvarchar(max) with allow nulls checked. >> >> >> >> > >> >> >> >> > "Cor Ligthert [MVP]" wrote: >> >> >> >> > >> >> >> >> >> Andrew, >> >> >> >> >> >> >> >> >> >> Nothing wrong with in my idea, however I would do it in its >> >> >> >> >> simplest >> >> >> >> >> format >> >> >> >> >> in this way. >> >> >> >> >> >> >> >> >> >> > Private Sub Button1_Click(ByVal sender As System.Object, >> >> >> >> >> > ByVal >> >> >> >> >> > e >> >> >> >> >> > As >> >> >> >> >> > System.EventArgs) Handles Button1.Click >> >> >> >> >> > >> >> >> >> >> > Dim conn As New SqlConnection("Server=apw-db;" & _ >> >> >> >> >> > "DataBase=APW-System; Integrated >> >> >> >> >> > Security=SSPI") >> >> >> >> >> > Dim sqlstr As String = "SELECT * FROM sysName" >> >> >> >> >> Dim da As new SqlDataAdapter(sqlstr, conn) >> >> >> >> >> > Dim ds As New DataSet >> >> >> >> >> Try >> >> >> >> >> > da.Fill(ds) >> >> >> >> >> MessageBox.Show(ds.Tables(0).Rows.Item("sysName")) >> >> >> >> >> 'trying >> >> >> >> >> to >> >> >> >> >> show >> >> >> >> >> what is in field >> >> >> >> >> Catch ex as Exception >> >> >> >> >> MessageBox.Show(ex.ToString) >> >> >> >> >> End Try >> >> >> >> >> > End Sub >> >> >> >> >> >> >> >> >> >> I hope this helps, >> >> >> >> >> >> >> >> >> >> Cor >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> "Andrew" <And***@discussions.microsoft.com> schreef in >> >> >> >> >> bericht >> >> >> >> >> news:0355ADCB-BE94-4D60-882A-E5D9ABDACDCD@microsoft.com... >> >> >> >> >> >I am simple tryint to learn how to use the ADO.NET code. Can >> >> >> >> >> >anybody >> >> >> >> >> >tell >> >> >> >> >> >me >> >> >> >> >> > if I am using it right or not? >> >> >> >> >> > >> >> >> >> >> > Imports System.Data.sqlclient >> >> >> >> >> > Imports System.Data >> >> >> >> >> > >> >> >> >> >> > Public Class Form1 >> >> >> >> >> > >> >> >> >> >> > Inherits System.Windows.Forms.Form >> >> >> >> >> > >> >> >> >> >> > Private Sub Button1_Click(ByVal sender As System.Object, >> >> >> >> >> > ByVal >> >> >> >> >> > e >> >> >> >> >> > As >> >> >> >> >> > System.EventArgs) Handles Button1.Click >> >> >> >> >> > >> >> >> >> >> > Dim conn As New SqlConnection("Server=apw-db;" & _ >> >> >> >> >> > "DataBase=APW-System; Integrated >> >> >> >> >> > Security=SSPI") >> >> >> >> >> > Dim sqlstr As String = "SELECT * FROM sysName" >> >> >> >> >> > Dim da As SqlDataAdapter >> >> >> >> >> > Dim ds As New DataSet >> >> >> >> >> > da = New SqlDataAdapter(sqlstr, conn) >> >> >> >> >> > da.Fill(ds) >> >> >> >> >> > Dim dt As DataTable = ds.Tables(0) >> >> >> >> >> > >> >> >> >> >> > MsgBox(dt.Rows.Item("sysName")) 'trying to show what >> >> >> >> >> > is >> >> >> >> >> > in >> >> >> >> >> > field >> >> >> >> >> > >> >> >> >> >> > End Sub >> >> >> >> >> > End Class >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> thanks for you help, I will defiantly work on that.
Show quoteHide quote "Stephany Young" wrote: > When you are using the SqlClient objects, DO NOT include the Provider clause > in the connection string. > > If you are using SQl Server authentication then the minimum connection > string is: > > Data Source=<server>;Initial Catalog=<database>;User > ID=<username>;Password=<password> > > where the tokens (<server>, <database>, <username> and <password>) are > replaced with your own values. > > The 'new' method for doing an insert is to instantiate a SqlCommand object > and call it's ExecuteNONQuery method: > > Dim _con As New SqlConnection(_connectionstring) > > Dim _com As New SqlCommand(_insertsqlstring, _con) > > _com.Parameters.Add(_parametername, _parametertype).Value = > _parametervalue > ' Add all required parameters > > _con.Open() > > _com.ExceuteNonQuery() > > _con.Close() > > I suggest you study the documentation relating to the > System.Data.SqlClient.SqlCommand class along with the documentation for > other related classes. > > > "Andrew" <And***@discussions.microsoft.com> wrote in message > news:AA56360C-730B-4E68-B907-5483C691D5CC@microsoft.com... > > Thanks for pointing that out, I was having a brain fart. At the time I got > > this reply back I was noticing that there was no command execution for the > > sql string. Not I am getting a reply back from the server, how ever I am > > not > > use to logging in with windows authentication. > > > > Is the provider string done the same way as in the previous version of > > adodb. This is my string with the previous version > > > > "Provider=SQLOLEDB.1;User ID=sa;password=" & sPassword & ";Initial > > Catalog=" > > & sDBName & ";Data Source = " & sServer & ";Use Procedure for > > Prepare=1;Auto > > Translate=True;Packet Size=4096" > > > > Is it the same in adodb.net or different? > > > > and if I was to update a database through a sql string with this code, Do > > I > > do the same type of execution with the update sql string? > > > > example of old: > > > > > > cmd.ActiveConnection = conn > > cmd.CommandText = "INSERT INTO driveMaster > > (driveID,sysID,evenID,driveDate,driveLET,driveTtl,driveFree)" & _ > > "VALUES (NEWID(), " & uID & ", 'ID3333', current_timestamp, > > '" & sD & "', '" & iTtl & "', '" & iFree & "')" > > cmd.CommandType = ADODB.CommandTypeEnum.adCmdText > > rs = cmd.Execute > > > > > > > > > > > > > > > > "Stephany Young" wrote: > > > >> You did it quite successfully in your original post. > >> > >> > >> "Andrew" <And***@discussions.microsoft.com> wrote in message > >> news:2E575AF0-4172-4920-A0F9-2F744BB19CA4@microsoft.com... > >> > how would I do that in .net? > >> > > >> > "Stephany Young" wrote: > >> > > >> >> Instantiate da. > >> >> > >> >> > >> >> "Andrew" <And***@discussions.microsoft.com> wrote in message > >> >> news:0AD0BAC4-522C-44D3-BCDE-63F08220BE02@microsoft.com... > >> >> > here is the new code: > >> >> > > >> >> > > >> >> > Imports System.Data.sqlclient > >> >> > Imports System.Data > >> >> > > >> >> > Public Class Form1 > >> >> > > >> >> > Inherits System.Windows.Forms.Form > >> >> > > >> >> > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As > >> >> > System.EventArgs) Handles Button1.Click > >> >> > > >> >> > Dim conn As New SqlConnection("Server=apw-db;" & _ > >> >> > "DataBase=APW-System; Integrated > >> >> > Security=SSPI") > >> >> > Dim sqlstr As String = "SELECT * FROM sysMaster WHERE > >> >> > sysName='IT_1'" > >> >> > Dim da As SqlDataAdapter > >> >> > Dim ds As New DataSet > >> >> > > >> >> > Try > >> >> > da.Fill(ds) > >> >> > > >> >> > > >> >> > MessageBox.Show(ds.Tables(0).Rows(0).Item("sysName").ToString) > >> >> > 'trying to show what is in field > >> >> > Catch ex As Exception > >> >> > MessageBox.Show(ex.ToString) > >> >> > > >> >> > End Try > >> >> > > >> >> > End Sub > >> >> > End Class > >> >> > > >> >> > > >> >> > > >> >> > "Cor Ligthert [MVP]" wrote: > >> >> > > >> >> >> > >> >> >> Can you show your complete new code again, > >> >> >> > >> >> >> Cor > >> >> >> > >> >> >> > >> >> >> "Andrew" <And***@discussions.microsoft.com> schreef in bericht > >> >> >> news:B317D639-6D4B-4562-A4F5-4DB895EC9AED@microsoft.com... > >> >> >> >I think the error is coming from the: > >> >> >> > > >> >> >> > da.fill(ds) ' function > >> >> >> > > >> >> >> > > >> >> >> > > >> >> >> > > >> >> >> > > >> >> >> > "Cor Ligthert [MVP]" wrote: > >> >> >> > > >> >> >> >> Andrew, > >> >> >> >> > >> >> >> >> Sorry, this can be > >> >> >> >> Cstr(ds.Tables(0).Rows(0).Item("sysName")) > >> >> >> >> ds.Tables(0).Rows(0).Item("sysName").ToString > >> >> >> >> Ctype(ds.Tables(0).Rows(0).Item("sysName"),String) > >> >> >> >> > >> >> >> >> Most people including me use the ToString, > >> >> >> >> > >> >> >> >> I have typed it in the message, looking at the major points. > >> >> >> >> > >> >> >> >> I hope it will go now, again not tested just typed. > >> >> >> >> > >> >> >> >> Cor > >> >> >> >> > >> >> >> >> > >> >> >> >> "Andrew" <And***@discussions.microsoft.com> schreef in bericht > >> >> >> >> news:077901A1-9479-4278-8E3C-37DEC01C7990@microsoft.com... > >> >> >> >> > when I put as you put I get an error : "System.data.datarow" > >> >> >> >> > cannot > >> >> >> >> > be > >> >> >> >> > converted to string. > >> >> >> >> > > >> >> >> >> > when I put > >> >> >> >> > convert.tostring(ds.Tables(0).Rows.Item("sysName"))) > >> >> >> >> > > >> >> >> >> > I get a new message: > >> >> >> >> > > >> >> >> >> > system.nullfreferenceExecptoin: Object Reference not set to > >> >> >> >> > instaance > >> >> >> >> > of > >> >> >> >> > an > >> >> >> >> > Object. > >> >> >> >> > as windowsApplication1.form1.button1_click() app path > >> >> >> >> > ADodb.net\windowsaplication1\form1.vb:line71 > >> >> >> >> > > >> >> >> >> > I have one row with information in this table and the field is > >> >> >> >> > a > >> >> >> >> > nvarchar(max) with allow nulls checked. > >> >> >> >> > > >> >> >> >> > "Cor Ligthert [MVP]" wrote: > >> >> >> >> > > >> >> >> >> >> Andrew, > >> >> >> >> >> > >> >> >> >> >> Nothing wrong with in my idea, however I would do it in its > >> >> >> >> >> simplest > >> >> >> >> >> format > >> >> >> >> >> in this way. > >> >> >> >> >> > >> >> >> >> >> > Private Sub Button1_Click(ByVal sender As System.Object, > >> >> >> >> >> > ByVal > >> >> >> >> >> > e > >> >> >> >> >> > As > >> >> >> >> >> > System.EventArgs) Handles Button1.Click > >> >> >> >> >> > > >> >> >> >> >> > Dim conn As New SqlConnection("Server=apw-db;" & _ > >> >> >> >> >> > "DataBase=APW-System; Integrated > >> >> >> >> >> > Security=SSPI") > >> >> >> >> >> > Dim sqlstr As String = "SELECT * FROM sysName" > >> >> >> >> >> Dim da As new SqlDataAdapter(sqlstr, conn) > >> >> >> >> >> > Dim ds As New DataSet > >> >> >> >> >> Try > >> >> >> >> >> > da.Fill(ds) > >> >> >> >> >> MessageBox.Show(ds.Tables(0).Rows.Item("sysName")) > >> >> >> >> >> 'trying > >> >> >> >> >> to > >> >> >> >> >> show > >> >> >> >> >> what is in field > >> >> >> >> >> Catch ex as Exception > >> >> >> >> >> MessageBox.Show(ex.ToString) > >> >> >> >> >> End Try > >> >> >> >> >> > End Sub > >> >> >> >> >> > >> >> >> >> >> I hope this helps, > >> >> >> >> >> > >> >> >> >> >> Cor > >> >> >> >> >> > >> >> >> >> >> > >> >> >> >> >> "Andrew" <And***@discussions.microsoft.com> schreef in > >> >> >> >> >> bericht > >> >> >> >> >> news:0355ADCB-BE94-4D60-882A-E5D9ABDACDCD@microsoft.com... > >> >> >> >> >> >I am simple tryint to learn how to use the ADO.NET code. Can > >> >> >> >> >> >anybody > >> >> >> >> >> >tell > >> >> >> >> >> >me > >> >> >> >> >> > if I am using it right or not? > >> >> >> >> >> > > >> >> >> >> >> > Imports System.Data.sqlclient > >> >> >> >> >> > Imports System.Data > >> >> >> >> >> > > >> >> >> >> >> > Public Class Form1 > >> >> >> >> >> > > >> >> >> >> >> > Inherits System.Windows.Forms.Form > >> >> >> >> >> > > >> >> >> >> >> > Private Sub Button1_Click(ByVal sender As System.Object, > >> >> >> >> >> > ByVal > >> >> >> >> >> > e > >> >> >> >> >> > As > >> >> >> >> >> > System.EventArgs) Handles Button1.Click > >> >> >> >> >> > > >> >> >> >> >> > Dim conn As New SqlConnection("Server=apw-db;" & _ > >> >> >> >> >> > "DataBase=APW-System; Integrated > >> >> >> >> >> > Security=SSPI") > >> >> >> >> >> > Dim sqlstr As String = "SELECT * FROM sysName" > >> >> >> >> >> > Dim da As SqlDataAdapter > >> >> >> >> >> > Dim ds As New DataSet > >> >> >> >> >> > da = New SqlDataAdapter(sqlstr, conn) > >> >> >> >> >> > da.Fill(ds) > >> >> >> >> >> > Dim dt As DataTable = ds.Tables(0) > >> >> >> >> >> > > >> >> >> >> >> > MsgBox(dt.Rows.Item("sysName")) 'trying to show what > >> >> >> >> >> > is > >> >> >> >> >> > in > >> >> >> >> >> > field > >> >> >> >> >> > > >> >> >> >> >> > End Sub > >> >> >> >> >> > End Class > >> >> >> >> >> > >> >> >> >> >> > >> >> >> >> >> > >> >> >> >> > >> >> >> >> > >> >> >> >> > >> >> >> > >> >> >> > >> >> >> > >> >> > >> >> > >> >> > >> > >> > >> > > > thanks for pointing that out, I was having a brian fart. At the time I got
this reply back I was noticing that there was no command execution for the sql string. Not I am getting a reply back from the server, how ever I am not use to loging in with windows authinication. Show quoteHide quote "Stephany Young" wrote: > You did it quite successfully in your original post. > > > "Andrew" <And***@discussions.microsoft.com> wrote in message > news:2E575AF0-4172-4920-A0F9-2F744BB19CA4@microsoft.com... > > how would I do that in .net? > > > > "Stephany Young" wrote: > > > >> Instantiate da. > >> > >> > >> "Andrew" <And***@discussions.microsoft.com> wrote in message > >> news:0AD0BAC4-522C-44D3-BCDE-63F08220BE02@microsoft.com... > >> > here is the new code: > >> > > >> > > >> > Imports System.Data.sqlclient > >> > Imports System.Data > >> > > >> > Public Class Form1 > >> > > >> > Inherits System.Windows.Forms.Form > >> > > >> > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As > >> > System.EventArgs) Handles Button1.Click > >> > > >> > Dim conn As New SqlConnection("Server=apw-db;" & _ > >> > "DataBase=APW-System; Integrated Security=SSPI") > >> > Dim sqlstr As String = "SELECT * FROM sysMaster WHERE > >> > sysName='IT_1'" > >> > Dim da As SqlDataAdapter > >> > Dim ds As New DataSet > >> > > >> > Try > >> > da.Fill(ds) > >> > > >> > > >> > MessageBox.Show(ds.Tables(0).Rows(0).Item("sysName").ToString) > >> > 'trying to show what is in field > >> > Catch ex As Exception > >> > MessageBox.Show(ex.ToString) > >> > > >> > End Try > >> > > >> > End Sub > >> > End Class > >> > > >> > > >> > > >> > "Cor Ligthert [MVP]" wrote: > >> > > >> >> > >> >> Can you show your complete new code again, > >> >> > >> >> Cor > >> >> > >> >> > >> >> "Andrew" <And***@discussions.microsoft.com> schreef in bericht > >> >> news:B317D639-6D4B-4562-A4F5-4DB895EC9AED@microsoft.com... > >> >> >I think the error is coming from the: > >> >> > > >> >> > da.fill(ds) ' function > >> >> > > >> >> > > >> >> > > >> >> > > >> >> > > >> >> > "Cor Ligthert [MVP]" wrote: > >> >> > > >> >> >> Andrew, > >> >> >> > >> >> >> Sorry, this can be > >> >> >> Cstr(ds.Tables(0).Rows(0).Item("sysName")) > >> >> >> ds.Tables(0).Rows(0).Item("sysName").ToString > >> >> >> Ctype(ds.Tables(0).Rows(0).Item("sysName"),String) > >> >> >> > >> >> >> Most people including me use the ToString, > >> >> >> > >> >> >> I have typed it in the message, looking at the major points. > >> >> >> > >> >> >> I hope it will go now, again not tested just typed. > >> >> >> > >> >> >> Cor > >> >> >> > >> >> >> > >> >> >> "Andrew" <And***@discussions.microsoft.com> schreef in bericht > >> >> >> news:077901A1-9479-4278-8E3C-37DEC01C7990@microsoft.com... > >> >> >> > when I put as you put I get an error : "System.data.datarow" > >> >> >> > cannot > >> >> >> > be > >> >> >> > converted to string. > >> >> >> > > >> >> >> > when I put convert.tostring(ds.Tables(0).Rows.Item("sysName"))) > >> >> >> > > >> >> >> > I get a new message: > >> >> >> > > >> >> >> > system.nullfreferenceExecptoin: Object Reference not set to > >> >> >> > instaance > >> >> >> > of > >> >> >> > an > >> >> >> > Object. > >> >> >> > as windowsApplication1.form1.button1_click() app path > >> >> >> > ADodb.net\windowsaplication1\form1.vb:line71 > >> >> >> > > >> >> >> > I have one row with information in this table and the field is a > >> >> >> > nvarchar(max) with allow nulls checked. > >> >> >> > > >> >> >> > "Cor Ligthert [MVP]" wrote: > >> >> >> > > >> >> >> >> Andrew, > >> >> >> >> > >> >> >> >> Nothing wrong with in my idea, however I would do it in its > >> >> >> >> simplest > >> >> >> >> format > >> >> >> >> in this way. > >> >> >> >> > >> >> >> >> > Private Sub Button1_Click(ByVal sender As System.Object, ByVal > >> >> >> >> > e > >> >> >> >> > As > >> >> >> >> > System.EventArgs) Handles Button1.Click > >> >> >> >> > > >> >> >> >> > Dim conn As New SqlConnection("Server=apw-db;" & _ > >> >> >> >> > "DataBase=APW-System; Integrated > >> >> >> >> > Security=SSPI") > >> >> >> >> > Dim sqlstr As String = "SELECT * FROM sysName" > >> >> >> >> Dim da As new SqlDataAdapter(sqlstr, conn) > >> >> >> >> > Dim ds As New DataSet > >> >> >> >> Try > >> >> >> >> > da.Fill(ds) > >> >> >> >> MessageBox.Show(ds.Tables(0).Rows.Item("sysName")) > >> >> >> >> 'trying > >> >> >> >> to > >> >> >> >> show > >> >> >> >> what is in field > >> >> >> >> Catch ex as Exception > >> >> >> >> MessageBox.Show(ex.ToString) > >> >> >> >> End Try > >> >> >> >> > End Sub > >> >> >> >> > >> >> >> >> I hope this helps, > >> >> >> >> > >> >> >> >> Cor > >> >> >> >> > >> >> >> >> > >> >> >> >> "Andrew" <And***@discussions.microsoft.com> schreef in bericht > >> >> >> >> news:0355ADCB-BE94-4D60-882A-E5D9ABDACDCD@microsoft.com... > >> >> >> >> >I am simple tryint to learn how to use the ADO.NET code. Can > >> >> >> >> >anybody > >> >> >> >> >tell > >> >> >> >> >me > >> >> >> >> > if I am using it right or not? > >> >> >> >> > > >> >> >> >> > Imports System.Data.sqlclient > >> >> >> >> > Imports System.Data > >> >> >> >> > > >> >> >> >> > Public Class Form1 > >> >> >> >> > > >> >> >> >> > Inherits System.Windows.Forms.Form > >> >> >> >> > > >> >> >> >> > Private Sub Button1_Click(ByVal sender As System.Object, ByVal > >> >> >> >> > e > >> >> >> >> > As > >> >> >> >> > System.EventArgs) Handles Button1.Click > >> >> >> >> > > >> >> >> >> > Dim conn As New SqlConnection("Server=apw-db;" & _ > >> >> >> >> > "DataBase=APW-System; Integrated > >> >> >> >> > Security=SSPI") > >> >> >> >> > Dim sqlstr As String = "SELECT * FROM sysName" > >> >> >> >> > Dim da As SqlDataAdapter > >> >> >> >> > Dim ds As New DataSet > >> >> >> >> > da = New SqlDataAdapter(sqlstr, conn) > >> >> >> >> > da.Fill(ds) > >> >> >> >> > Dim dt As DataTable = ds.Tables(0) > >> >> >> >> > > >> >> >> >> > MsgBox(dt.Rows.Item("sysName")) 'trying to show what is > >> >> >> >> > in > >> >> >> >> > field > >> >> >> >> > > >> >> >> >> > End Sub > >> >> >> >> > End Class > >> >> >> >> > >> >> >> >> > >> >> >> >> > >> >> >> > >> >> >> > >> >> >> > >> >> > >> >> > >> >> > >> > >> > >> > > >
Show quote
Hide quote
>
> Imports System.Data.sqlclient > Imports System.Data > > Public Class Form1 > > Inherits System.Windows.Forms.Form > > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As > System.EventArgs) Handles Button1.Click > > Dim conn As New SqlConnection("Server=apw-db;" & _ > "DataBase=APW-System; Integrated Security=SSPI") > Dim sqlstr As String = "SELECT * FROM sysMaster WHERE > sysName='IT_1'" > Dim da As SqlDataAdapter >> >> >> Dim da As new SqlDataAdapter(sqlstr, conn)
Launching Web site for help
Cross: Access speed Small question? Why does this not work? What am I doing wrong? PrintDocument_PrintPage goes into endless loop until e.HasMorePages=False vbc : error BC30420: 'Sub Main' was not found in 'Product'. Is it necessary to close a local OleDbDataReader before exit function? VB Smart Devivce Programming Changing user interface DataGridView Questions |
|||||||||||||||||||||||