melkanzi Posted November 21, 2006 Posted November 21, 2006 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 Quote
Administrators PlausiblyDamp Posted November 21, 2006 Administrators Posted November 21, 2006 Without seeing a bit more information (or some code) it is difficult to say what the problem could be. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
melkanzi Posted November 21, 2006 Author Posted November 21, 2006 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 Quote
michaelrawi Posted November 22, 2006 Posted November 22, 2006 Have you set SQL Server 2005 to enable remote connection ? It's off by default. And when it's off, no program can access SQL Server 2005. Quote
Administrators PlausiblyDamp Posted November 22, 2006 Administrators Posted November 22, 2006 Does it give any errors when you try this? Either via a stored proc or by building the string up manually? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
melkanzi Posted November 22, 2006 Author Posted November 22, 2006 No errors are given. It even returns 1 as the number of rows affected. but physically no changes. Quote
FZelle Posted November 22, 2006 Posted November 22, 2006 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. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.