all groups > vb.net data > june 2005 >
vb.net data :
I am doing something wrong (ADO.NET)
I am trying to get an example from a book to work... I am new to dot net so it is likely I am doing something wrong. I added a new module and created the function below which is run from a button. When I click the button, nothing hapens (or at least I do not see anything happen). Function GrabData() Dim strSQL As String Dim strConn As String = "Provider=SQLOLEDB;Data Source=(local);" & _ "Initial Catalog=Northwind;Trusted_Connection=Yes;" Dim cn As New OleDbConnection(strConn) cn.Open() strSQL = "Select CustomerID , CompanyName from Customers" Dim cmd As New OleDbCommand(strSQL, cn) Dim rdr As OleDbDataReader = cmd.ExecuteReader() While rdr.Read() Console.WriteLine(rdr("CustomerID") & " - " & rdr("CompanyName")) End While rdr.Close() End Function
Hi, You are writing the output to the console. It will create a console window and close it as soon as it is done. Try writing to the output window with trace.writeline instead. Dont forget to close the connection when you are done with it. While rdr.Read() Trace.WriteLine(rdr("CustomerID") & " - " & rdr("CompanyName")) End While rdr.Close() cn.close Ken ------------------------ [quoted text, click to view] "Rob" <rwchome@comcast.net> wrote in message news:DaidneR6rZva2CvfRVn-vg@comcast.com...
I am trying to get an example from a book to work... I am new to dot net so it is likely I am doing something wrong. I added a new module and created the function below which is run from a button. When I click the button, nothing hapens (or at least I do not see anything happen). Function GrabData() Dim strSQL As String Dim strConn As String = "Provider=SQLOLEDB;Data Source=(local);" & _ "Initial Catalog=Northwind;Trusted_Connection=Yes;" Dim cn As New OleDbConnection(strConn) cn.Open() strSQL = "Select CustomerID , CompanyName from Customers" Dim cmd As New OleDbCommand(strSQL, cn) Dim rdr As OleDbDataReader = cmd.ExecuteReader() While rdr.Read() Console.WriteLine(rdr("CustomerID") & " - " & rdr("CompanyName")) End While rdr.Close() End Function
Hi Ken, I tried that but I still see nothing... Do I need to have it bound to a control on the form ? Thanks, Rob [quoted text, click to view] "Ken Tucker [MVP]" <vb2ae@bellsouth.net> wrote in message news:O0OxxYXdFHA.580@TK2MSFTNGP15.phx.gbl... > Hi, > > You are writing the output to the console. It will create a > console window and close it as soon as it is done. Try writing to the > output window with trace.writeline instead. Dont forget to close the > connection when you are done with it. > > > While rdr.Read() > > Trace.WriteLine(rdr("CustomerID") & " - " & rdr("CompanyName")) > > End While > > rdr.Close() > > cn.close > > Ken > ------------------------ > > "Rob" <rwchome@comcast.net> wrote in message > news:DaidneR6rZva2CvfRVn-vg@comcast.com... > I am trying to get an example from a book to work... > > I am new to dot net so it is likely I am doing something wrong. > > I added a new module and created the function below which is run from a > button. When I click the button, nothing hapens (or at least I do not > see > anything happen). > > Function GrabData() > > Dim strSQL As String > > Dim strConn As String = "Provider=SQLOLEDB;Data Source=(local);" & _ > > "Initial Catalog=Northwind;Trusted_Connection=Yes;" > > Dim cn As New OleDbConnection(strConn) > > cn.Open() > > strSQL = "Select CustomerID , CompanyName from Customers" > > Dim cmd As New OleDbCommand(strSQL, cn) > > Dim rdr As OleDbDataReader = cmd.ExecuteReader() > > While rdr.Read() > > Console.WriteLine(rdr("CustomerID") & " - " & rdr("CompanyName")) > > End While > > rdr.Close() > > > > End Function > > > >
Hi, Dim conn As SqlConnection Dim strConn As String Dim dr As SqlDataReader Dim cmd As SqlCommand Dim strSql As String strConn = "Server = (local);" strConn &= "Database = NorthWind;" strConn &= "Integrated Security = SSPI;" conn = New SqlConnection(strConn) conn.Open() strSQL = "Select CustomerID , CompanyName from Customers" cmd = New SqlCommand(strSql, conn) dr = cmd.ExecuteReader() Do While dr.Read 'ComboBox1.Items.Add(drCustomer.Item("CustomerID").ToString) Trace.WriteLine(dr("CustomerID") & " - " & dr("CompanyName")) Loop conn.Close() Ken -------------------- [quoted text, click to view] "Rob" <rwchome@comcast.net> wrote in message news:foidnecmnMolJyvfRVn-pw@comcast.com...
Hi Ken, I tried that but I still see nothing... Do I need to have it bound to a control on the form ? Thanks, Rob [quoted text, click to view] "Ken Tucker [MVP]" <vb2ae@bellsouth.net> wrote in message news:O0OxxYXdFHA.580@TK2MSFTNGP15.phx.gbl... > Hi, > > You are writing the output to the console. It will create a > console window and close it as soon as it is done. Try writing to the > output window with trace.writeline instead. Dont forget to close the > connection when you are done with it. > > > While rdr.Read() > > Trace.WriteLine(rdr("CustomerID") & " - " & rdr("CompanyName")) > > End While > > rdr.Close() > > cn.close > > Ken > ------------------------ > > "Rob" <rwchome@comcast.net> wrote in message > news:DaidneR6rZva2CvfRVn-vg@comcast.com... > I am trying to get an example from a book to work... > > I am new to dot net so it is likely I am doing something wrong. > > I added a new module and created the function below which is run from a > button. When I click the button, nothing hapens (or at least I do not > see > anything happen). > > Function GrabData() > > Dim strSQL As String > > Dim strConn As String = "Provider=SQLOLEDB;Data Source=(local);" & _ > > "Initial Catalog=Northwind;Trusted_Connection=Yes;" > > Dim cn As New OleDbConnection(strConn) > > cn.Open() > > strSQL = "Select CustomerID , CompanyName from Customers" > > Dim cmd As New OleDbCommand(strSQL, cn) > > Dim rdr As OleDbDataReader = cmd.ExecuteReader() > > While rdr.Read() > > Console.WriteLine(rdr("CustomerID") & " - " & rdr("CompanyName")) > > End While > > rdr.Close() > > > > End Function > > > >
Thanks Terry, I made the change, but I did not see it do anything... [quoted text, click to view] "Terry Olsen" <tolsen64@hotmail.com> wrote in message news:eGbmoGmdFHA.2420@TK2MSFTNGP12.phx.gbl... > Try using Debug.WriteLine instead. > > "Rob" <rwchome@comcast.net> wrote in message > news:wZmdnc_RS4PCmyXfRVn-sQ@comcast.com... >> Hi Ken, >> >> Thanks, that did get the data to show up in the Combo Box, however, the >> Trace.Writeline does not appear to be working. >> >> Also, how do you populate a form control from a Module ? >> >> Thanks, >> Rob >> >> >> "Ken Tucker [MVP]" <vb2ae@bellsouth.net> wrote in message >> news:%23Btl6CedFHA.1044@TK2MSFTNGP10.phx.gbl... >>> Hi, >>> >>> Dim conn As SqlConnection >>> Dim strConn As String >>> Dim dr As SqlDataReader >>> Dim cmd As SqlCommand >>> Dim strSql As String >>> >>> strConn = "Server = (local);" >>> strConn &= "Database = NorthWind;" >>> strConn &= "Integrated Security = SSPI;" >>> >>> conn = New SqlConnection(strConn) >>> >>> conn.Open() >>> >>> strSQL = "Select CustomerID , CompanyName from Customers" >>> >>> cmd = New SqlCommand(strSql, conn) >>> >>> dr = cmd.ExecuteReader() >>> >>> Do While dr.Read >>> 'ComboBox1.Items.Add(drCustomer.Item("CustomerID").ToString) >>> Trace.WriteLine(dr("CustomerID") & " - " & dr("CompanyName")) >>> Loop >>> conn.Close() >>> >>> >>> Ken >>> -------------------- >>> "Rob" <rwchome@comcast.net> wrote in message >>> news:foidnecmnMolJyvfRVn-pw@comcast.com... >>> Hi Ken, >>> >>> I tried that but I still see nothing... >>> >>> Do I need to have it bound to a control on the form ? >>> >>> Thanks, >>> Rob >>> >>> >>> >>> "Ken Tucker [MVP]" <vb2ae@bellsouth.net> wrote in message >>> news:O0OxxYXdFHA.580@TK2MSFTNGP15.phx.gbl... >>>> Hi, >>>> >>>> You are writing the output to the console. It will create a >>>> console window and close it as soon as it is done. Try writing to the >>>> output window with trace.writeline instead. Dont forget to close the >>>> connection when you are done with it. >>>> >>>> >>>> While rdr.Read() >>>> >>>> Trace.WriteLine(rdr("CustomerID") & " - " & rdr("CompanyName")) >>>> >>>> End While >>>> >>>> rdr.Close() >>>> >>>> cn.close >>>> >>>> Ken >>>> ------------------------ >>>> >>>> "Rob" <rwchome@comcast.net> wrote in message >>>> news:DaidneR6rZva2CvfRVn-vg@comcast.com... >>>> I am trying to get an example from a book to work... >>>> >>>> I am new to dot net so it is likely I am doing something wrong. >>>> >>>> I added a new module and created the function below which is run from a >>>> button. When I click the button, nothing hapens (or at least I do not >>>> see >>>> anything happen). >>>> >>>> Function GrabData() >>>> >>>> Dim strSQL As String >>>> >>>> Dim strConn As String = "Provider=SQLOLEDB;Data Source=(local);" & _ >>>> >>>> "Initial Catalog=Northwind;Trusted_Connection=Yes;" >>>> >>>> Dim cn As New OleDbConnection(strConn) >>>> >>>> cn.Open() >>>> >>>> strSQL = "Select CustomerID , CompanyName from Customers" >>>> >>>> Dim cmd As New OleDbCommand(strSQL, cn) >>>> >>>> Dim rdr As OleDbDataReader = cmd.ExecuteReader() >>>> >>>> While rdr.Read() >>>> >>>> Console.WriteLine(rdr("CustomerID") & " - " & rdr("CompanyName")) >>>> >>>> End While >>>> >>>> rdr.Close() >>>> >>>> >>>> >>>> End Function >>>> >>>> >>>> >>>> >>> >>> >>> >> >> > >
Try using Debug.WriteLine instead. [quoted text, click to view] "Rob" <rwchome@comcast.net> wrote in message news:wZmdnc_RS4PCmyXfRVn-sQ@comcast.com... > Hi Ken, > > Thanks, that did get the data to show up in the Combo Box, however, the > Trace.Writeline does not appear to be working. > > Also, how do you populate a form control from a Module ? > > Thanks, > Rob > > > "Ken Tucker [MVP]" <vb2ae@bellsouth.net> wrote in message > news:%23Btl6CedFHA.1044@TK2MSFTNGP10.phx.gbl... >> Hi, >> >> Dim conn As SqlConnection >> Dim strConn As String >> Dim dr As SqlDataReader >> Dim cmd As SqlCommand >> Dim strSql As String >> >> strConn = "Server = (local);" >> strConn &= "Database = NorthWind;" >> strConn &= "Integrated Security = SSPI;" >> >> conn = New SqlConnection(strConn) >> >> conn.Open() >> >> strSQL = "Select CustomerID , CompanyName from Customers" >> >> cmd = New SqlCommand(strSql, conn) >> >> dr = cmd.ExecuteReader() >> >> Do While dr.Read >> 'ComboBox1.Items.Add(drCustomer.Item("CustomerID").ToString) >> Trace.WriteLine(dr("CustomerID") & " - " & dr("CompanyName")) >> Loop >> conn.Close() >> >> >> Ken >> -------------------- >> "Rob" <rwchome@comcast.net> wrote in message >> news:foidnecmnMolJyvfRVn-pw@comcast.com... >> Hi Ken, >> >> I tried that but I still see nothing... >> >> Do I need to have it bound to a control on the form ? >> >> Thanks, >> Rob >> >> >> >> "Ken Tucker [MVP]" <vb2ae@bellsouth.net> wrote in message >> news:O0OxxYXdFHA.580@TK2MSFTNGP15.phx.gbl... >>> Hi, >>> >>> You are writing the output to the console. It will create a >>> console window and close it as soon as it is done. Try writing to the >>> output window with trace.writeline instead. Dont forget to close the >>> connection when you are done with it. >>> >>> >>> While rdr.Read() >>> >>> Trace.WriteLine(rdr("CustomerID") & " - " & rdr("CompanyName")) >>> >>> End While >>> >>> rdr.Close() >>> >>> cn.close >>> >>> Ken >>> ------------------------ >>> >>> "Rob" <rwchome@comcast.net> wrote in message >>> news:DaidneR6rZva2CvfRVn-vg@comcast.com... >>> I am trying to get an example from a book to work... >>> >>> I am new to dot net so it is likely I am doing something wrong. >>> >>> I added a new module and created the function below which is run from a >>> button. When I click the button, nothing hapens (or at least I do not >>> see >>> anything happen). >>> >>> Function GrabData() >>> >>> Dim strSQL As String >>> >>> Dim strConn As String = "Provider=SQLOLEDB;Data Source=(local);" & _ >>> >>> "Initial Catalog=Northwind;Trusted_Connection=Yes;" >>> >>> Dim cn As New OleDbConnection(strConn) >>> >>> cn.Open() >>> >>> strSQL = "Select CustomerID , CompanyName from Customers" >>> >>> Dim cmd As New OleDbCommand(strSQL, cn) >>> >>> Dim rdr As OleDbDataReader = cmd.ExecuteReader() >>> >>> While rdr.Read() >>> >>> Console.WriteLine(rdr("CustomerID") & " - " & rdr("CompanyName")) >>> >>> End While >>> >>> rdr.Close() >>> >>> >>> >>> End Function >>> >>> >>> >>> >> >> >> > >
Hi Ken, Thanks, that did get the data to show up in the Combo Box, however, the Trace.Writeline does not appear to be working. Also, how do you populate a form control from a Module ? Thanks, Rob [quoted text, click to view] "Ken Tucker [MVP]" <vb2ae@bellsouth.net> wrote in message news:%23Btl6CedFHA.1044@TK2MSFTNGP10.phx.gbl... > Hi, > > Dim conn As SqlConnection > Dim strConn As String > Dim dr As SqlDataReader > Dim cmd As SqlCommand > Dim strSql As String > > strConn = "Server = (local);" > strConn &= "Database = NorthWind;" > strConn &= "Integrated Security = SSPI;" > > conn = New SqlConnection(strConn) > > conn.Open() > > strSQL = "Select CustomerID , CompanyName from Customers" > > cmd = New SqlCommand(strSql, conn) > > dr = cmd.ExecuteReader() > > Do While dr.Read > 'ComboBox1.Items.Add(drCustomer.Item("CustomerID").ToString) > Trace.WriteLine(dr("CustomerID") & " - " & dr("CompanyName")) > Loop > conn.Close() > > > Ken > -------------------- > "Rob" <rwchome@comcast.net> wrote in message > news:foidnecmnMolJyvfRVn-pw@comcast.com... > Hi Ken, > > I tried that but I still see nothing... > > Do I need to have it bound to a control on the form ? > > Thanks, > Rob > > > > "Ken Tucker [MVP]" <vb2ae@bellsouth.net> wrote in message > news:O0OxxYXdFHA.580@TK2MSFTNGP15.phx.gbl... >> Hi, >> >> You are writing the output to the console. It will create a >> console window and close it as soon as it is done. Try writing to the >> output window with trace.writeline instead. Dont forget to close the >> connection when you are done with it. >> >> >> While rdr.Read() >> >> Trace.WriteLine(rdr("CustomerID") & " - " & rdr("CompanyName")) >> >> End While >> >> rdr.Close() >> >> cn.close >> >> Ken >> ------------------------ >> >> "Rob" <rwchome@comcast.net> wrote in message >> news:DaidneR6rZva2CvfRVn-vg@comcast.com... >> I am trying to get an example from a book to work... >> >> I am new to dot net so it is likely I am doing something wrong. >> >> I added a new module and created the function below which is run from a >> button. When I click the button, nothing hapens (or at least I do not >> see >> anything happen). >> >> Function GrabData() >> >> Dim strSQL As String >> >> Dim strConn As String = "Provider=SQLOLEDB;Data Source=(local);" & _ >> >> "Initial Catalog=Northwind;Trusted_Connection=Yes;" >> >> Dim cn As New OleDbConnection(strConn) >> >> cn.Open() >> >> strSQL = "Select CustomerID , CompanyName from Customers" >> >> Dim cmd As New OleDbCommand(strSQL, cn) >> >> Dim rdr As OleDbDataReader = cmd.ExecuteReader() >> >> While rdr.Read() >> >> Console.WriteLine(rdr("CustomerID") & " - " & rdr("CompanyName")) >> >> End While >> >> rdr.Close() >> >> >> >> End Function >> >> >> >> > > >
Don't see what you're looking for? Try a search.
|
|
|