1. I have created sql connection to sql server 2000 from a vb.net form. However, I just want to make the connection class and I also want to know how to call that connection class from different forms to connect to sql server 2000.
2. Can I use the query from this class? Because, this connection class will be used by a number of forms.
3. TextBox1.Text, TextBox2.Text, TextBox2.Text are also not recognized by this connection class.
The connection that I've created is as follows:
Expand|Select|Wrap|Line Numbers
- Public Class Connection
- Private Sub btnConnect_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConnect.Click
- Dim fir As String
- Dim sec As String
- Dim age As Integer
- fir = TextBox1.Text
- sec = TextBox2.Text
- age = TextBox3.Text
- Dim strCNStr As String = "Data Source=ITSAD;Initial Catalog=Inspection;User ID=sa;Password=;"
- Dim cnDB As System.Data.SqlClient.SqlConnection = New System.Data.SqlClient.SqlConnection
- Dim cmdDB As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand("Insert into Branch(Fname,Lname,age) VALUES ('" & fir & "','" & sec & "','" & age & "')", cnDB)
- Dim rdAuther As System.Data.SqlClient.SqlDataReader
- cnDB.ConnectionString = strCNStr
- cnDB.Open()
- rdAuther = cmdDB.ExecuteReader()
- rdAuther.Close()
- cnDB.Close()
- End Sub
- End Class
Thank you