Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi,

I'm 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

Posted

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??

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

Posted

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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...