SQL 2005 Express

melkanzi

Active member
Joined
Jul 9, 2006
Messages
29
Hi,
Im working on VB 2005 and SQL 2005 express. I have created a number of tables but i cant insert into them from VB. I have tried every possible way of inserting into the tables and still no hope.
What is wrong? What am i missing out?

Thanks
 
Sample Code

These are the attempts i made to update the table. I have a stored procedure called AddNewUser that accepts the user id and the password.
I have tried creating single rows then adding them to the dataset but it also doesnt work.
I wrote the SQL command and it also doenst work.
What should i do??
Code:
Try
                Me.InsCom.CommandText = "Insert into Users values(" & Me.txtUsername.Text & "," & Me.txtPassword.Text & ",User)"
                Me.InsCom.Connection = Me.Con
                Me.DAUser.InsertCommand = InsCom
                Con.Open()
                Me.InsCom.CommandText = "AddNewUser"
                Me.InsCom.CommandType = CommandType.StoredProcedure
                Me.InsCom.Parameters.Add("@userid", SqlDbType.NVarChar, 50).Value = Me.txtUsername.Text
                Me.InsCom.Parameters.Add("@password", SqlDbType.NVarChar, 50).Value = Me.txtPassword.Text


                Me.InsCom.Parameters.Add(New SqlClient.SqlParameter("@userid", SqlDbType.NVarChar))
                Me.InsCom.Parameters.Add(New SqlClient.SqlParameter("@password", SqlDbType.NVarChar))
                Me.InsCom.Parameters("@userid").Value = Me.txtUsername.Text
                Me.InsCom.Parameters("@password").Value = Me.txtPassword.Text

                Me.DAUser.InsertCommand.Parameters.Item("@username").Value = Me.txtUsername.Text
                Me.DAUser.InsertCommand.Parameters.Item("@password").Value = Me.txtPassword.Text
                rows = Me.DAUser.InsertCommand.ExecuteNonQuery
                Dim dr2 As DataRow = Me.QrsDataSet1.ViewAllUsers.NewRow
                dr2.Item(0) = Me.txtUsername.Text
                dr2.Item(1) = Me.txtPassword.Text
                Me.QrsDataSet1.ViewAllUsers.Rows.Add(dr2)
                MessageBox.Show(Me.QrsDataSet1.ViewAllUsers.Rows.Count)
                rows = Me.DAUser.Update(Me.QrsDataSet1.ViewAllUsers)
                Me.DAUser.Fill(Me.QrsDataSet1.ViewAllUsers)
                Me.InsCom.Dispose()
                Con.Close()

                If rows = 1 Then
                    MessageBox.Show("Added")
                Else
                    MessageBox.Show("Not Added 1")
                End If
 
No errors are given. It even returns 1 as the number of rows affected. but physically no changes.
 
If you are useing the Database in Filemode, and you have the MDF in your project,
than the file gets copied everytime you start the software, so all changes are overwritten.
 
Back
Top