954,541 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Inserting into sql database

can someone help me with why this code is not inserting into the database

Dim MyConnection As SqlConnection

        Dim sqlstring As String = "INSERT INTO Workers (FName, LName, FullName)  VALUES ('" & Me.txtName.Text & "', '" & Me.txtSurname.Text & "', '" & Me.txtFullName.Text & "')"
        'Dim data_base As String = " C:\Documents and Settings\admin\Desktop\OCSWalkthrough\OCSWalkthrough\App_Data\Testing_DB.sdf"
        Dim data_base As String = " Data Source=NetServer;Initial Catalog=Testing_DB;User ID=xx;Password=xxxxxx"

        MyConnection = New SqlConnection("Data Source=" & data_base)
        Dim concom As SqlCommand = MyConnection.CreateCommand()


        MyConnection.Open()

        Dim cmnd As SqlCommand = New SqlCommand(sqlstring, MyConnection)

        cmnd.ExecuteNonQuery()        ' Execute the command here

        'and then read
        Dim myreader As SqlDataReader

        myreader = cmnd.ExecuteReader

        MyConnection.Close()
tendaimare
Junior Poster in Training
71 posts since Nov 2010
Reputation Points: 10
Solved Threads: 0
 

I got it

Dim MyConnection As SqlConnection
        Dim sqlstring As String = "INSERT INTO Workers (First_Name, Last_Name, Full_Name)  VALUES ('" & Me.txtName.Text & "', '" & Me.txtLastName.Text & "', '" & Me.txtFullName.Text & "')"
        Dim data_base As String = " Data Source=siv01-win1.wadns.net;Initial Catalog=Testing_DB;User ID=sa;Password=1234"
        MyConnection = New SqlConnection(data_base)
        Dim concom As SqlCommand = MyConnection.CreateCommand()
        MyConnection.Open()
        Dim cmnd As SqlCommand = New SqlCommand(sqlstring, MyConnection)
        cmnd.ExecuteNonQuery()        ' Execute the command here
tendaimare
Junior Poster in Training
71 posts since Nov 2010
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: