Inserting Into Database Not Working

rune72

New member
Joined
Dec 26, 2007
Messages
2
Programming Experience
1-3
I am using vb.net 2008 and I have created a test screen with a Datagridview on it that is displaying some basic login details from the login table. The Datagridview is not bound to anything. The login table is within an sql server express database, and i have a table adapter with an insert query that is a stored procedures within the DB.

This code seems to work fine in that the record will appear within the Datagridview after the insert code runs...but no record is being entered into the login Table.


VB.NET:
Dim TableAdapter As New LoginTableAdapters.LogInTableAdapter
        Dim connection As SqlClient.SqlConnection = _
New SqlClient.SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True;User Instance=True")
        connection.Open()
        Try
            Dim command As SqlClient.SqlCommand = New SqlClient.SqlCommand("InsertQuery", connection)
            command.CommandType = CommandType.StoredProcedure

            command.Parameters.Add("@liID", SqlDbType.BigInt, 8).Value = 6
            command.Parameters.Add("@Username", SqlDbType.VarChar, 50).Value = "test@test.com.au"
            command.Parameters.Add("@Password", SqlDbType.VarChar, 50).Value = "test"
            command.ExecuteNonQuery()

        Catch ex As Exception
            MsgBox(ex.Source & vbCrLf & ex.Message)
        Finally
            DataGridView1.DataSource = TableAdapter.GetData
        End Try

any help would be great....
 
i agree totally..it should be in the db..and the TableAdapter.GetData statement should only return what is in the db..however its not...after i click on the insert it appears in the datagridview...in the database explorer..i refresh the whole database...and open the login table...no data in it. If i rerun the program...the inserted row will appear in the gridview..for about 1 minute..then after that..its gone..i've even remade the screen...the db..the table..the whole lot..still get the same problem.

any ideas...im out of them
 
You're looking in the WRONG PLACE, as I have already said. You're looking at your original source database, not the one copied to the output folder. It's the one in the output folder that you're connecting to, NOT the one in the source folder.
 
Back
Top