
**Hi, I tried to insert into DB using textbox in a form using vb by visual studio 2010 but its always catch an error [Cannot open database "4" requested by the login. The login failed. Login failed for user 'sa'] i tried to get a solution for this error this the code i used**
Imports System.Data Imports System.Data.SqlClient
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim myconn As SqlConnection Dim cmd As SqlCommand Dim sqlString, Asd, Lays As String
Asd = ATextBox.Text
Lays = BTextBox.Text
myconn = New SqlConnection("server=localhost;" & "Initial Catalog=4;" & "User Id=sa;" & "Password=123;")
myconn.Open()
sqlString = "INSERT INTO Table1 (A , B) VALUES ('" + Asd + "','" + Lays + "') "
cmd = New SqlCommand(sqlString, myconn)
cmd.ExecuteNonQuery()
myconn.Close()
End Sub
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.