hi
i am new to dot net....m trying to access sqlserver management studio database using forms in vb.net...m using a button and i want to get access to the database when i click on that button....the code is given below....wen i tried the same code without using forms,this is working fine but it is not working when i use forms....
Imports System.Data.SqlClient
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim strcon As String = "Data Source=.\sqlexpress;Initial Catalog=employee;Integrated Security=True"
Dim con As SqlConnection
Dim cmd As SqlCommand
Dim dr As SqlDataReader
con = New SqlConnection(strcon)
cmd = New SqlCommand("select * from employee", con)
con.Open()
dr = cmd.ExecuteReader()
While dr.Read()
Console.Write(dr.Item(0))
Console.Write(dr.Item(1))
Console.Write(dr.Item(2))
End While
con.Close()
Console.ReadLine()
End Sub
End Class
m not getting any output using this code....please tell me where i went wrong...plz help me...it is urgent
5 Replies - 1358 Views - Last Post: 04 March 2009 - 05:30 PM
#1
connecting forms to sqlserver database using vb.net
Posted 04 March 2009 - 03:30 PM
Replies To: connecting forms to sqlserver database using vb.net
#2
Re: connecting forms to sqlserver database using vb.net
Posted 04 March 2009 - 04:47 PM
try this, add three textboxes to your form
and then change your code to this
and then change your code to this
textbox1.text = (dr.Item(0)) textbox1.text = (dr.Item(1)) textbox1.text = (dr.Item(2))
#3
Re: connecting forms to sqlserver database using vb.net
Posted 04 March 2009 - 05:04 PM
rpm, on 4 Mar, 2009 - 02:30 PM, said:
hi
i am new to dot net....m trying to access sqlserver management studio database using forms in vb.net...m using a button and i want to get access to the database when i click on that button....the code is given below....wen i tried the same code without using forms,this is working fine but it is not working when i use forms....
Imports System.Data.SqlClient
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim strcon As String = "Data Source=.\sqlexpress;Initial Catalog=employee;Integrated Security=True"
Dim con As SqlConnection
Dim cmd As SqlCommand
Dim dr As SqlDataReader
con = New SqlConnection(strcon)
cmd = New SqlCommand("select * from employee", con)
con.Open()
dr = cmd.ExecuteReader()
While dr.Read()
'Change those lines
Console.Write(dr.Item(0))
Console.Write(dr.Item(1))
Console.Write(dr.Item(2))
'so that you use ListBox1 control its on the toolBox
'with
ListBox1.Items.add(dr.Item(0) & " " & dr.Item(1) & " " & dr.Item(2))
End While
con.Close()
Console.ReadLine()
End Sub
End Class
m not getting any output using this code....please tell me where i went wrong...plz help me...it is urgent
i am new to dot net....m trying to access sqlserver management studio database using forms in vb.net...m using a button and i want to get access to the database when i click on that button....the code is given below....wen i tried the same code without using forms,this is working fine but it is not working when i use forms....
Imports System.Data.SqlClient
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim strcon As String = "Data Source=.\sqlexpress;Initial Catalog=employee;Integrated Security=True"
Dim con As SqlConnection
Dim cmd As SqlCommand
Dim dr As SqlDataReader
con = New SqlConnection(strcon)
cmd = New SqlCommand("select * from employee", con)
con.Open()
dr = cmd.ExecuteReader()
While dr.Read()
'Change those lines
Console.Write(dr.Item(0))
Console.Write(dr.Item(1))
Console.Write(dr.Item(2))
'so that you use ListBox1 control its on the toolBox
'with
ListBox1.Items.add(dr.Item(0) & " " & dr.Item(1) & " " & dr.Item(2))
End While
con.Close()
Console.ReadLine()
End Sub
End Class
m not getting any output using this code....please tell me where i went wrong...plz help me...it is urgent
#4
Re: connecting forms to sqlserver database using vb.net
Posted 04 March 2009 - 05:15 PM
thx for replying me...
it worked but d problem now is that
the employee table contains 3 columns and 4 rows
once i used 3 textboxes, it is showing me only last row values...it is not the above ones....
wat shuld i do now??please reply
it worked but d problem now is that
the employee table contains 3 columns and 4 rows
once i used 3 textboxes, it is showing me only last row values...it is not the above ones....
wat shuld i do now??please reply
#5
Re: connecting forms to sqlserver database using vb.net
Posted 04 March 2009 - 05:22 PM
well using the text boxes just showed that your code works.
if you want to display all the records you could have a look at something like what jackozi suggests or you could stick with the text boxes and add some functionality to navigate between records.
Check out the tutorial section, there are some there that should help you
if you want to display all the records you could have a look at something like what jackozi suggests or you could stick with the text boxes and add some functionality to navigate between records.
Check out the tutorial section, there are some there that should help you
#6
Re: connecting forms to sqlserver database using vb.net
Posted 04 March 2009 - 05:30 PM
@Damage and jackozi
thx a lot...
it worked now...
thx a lot...
it worked now...
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote



|