What I ask can be very familiar to most of you. So, please don't point me a URL in MSDN, I can't understand the stuff there. Instead please add the "lacking" codes and help me to complete the code.I need to store First Name and Last Name of userswhich come as user inputs through text boxes in a web form to an existing data table as a new data row.I used DataSets. I heard it is bulky. Is there any otherway of achieving it? I have included the databaseconnection in a method that is called for the clickevent of the submit button. Instead, Should I includeit in the Page load event? I also want to know weather there is a way to give relative paths for database connection instead of an absolute one which won't be practical when I move the stuff to a web server.Below I have included the complete code even withHTML. The error I get is "Update requires a valid InsertCommand when passed DataRow collection with new rows"It occurs due to the statement,objCmd.Update(ds, "contacts")Please help me to complete the code. I am a trainee and this is a practice project thatI should submit. I couldn't complete it for2 weeks. I made forum posts and got MSDNlinks. Please don't do that. Just tell me what code to where I should add. I really appreciate yourhelp. Here is the code,sub Add(obj as object, e as EventArgs)dim objConn as new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Inetpub\wwwroot\users\database\users.mdb")objConn.Open()dim objCmd as new OleDbDataAdapter("select * from contacts", objConn)dim ds as DataSet = new DataSet()objCmd.Fill(ds, "contacts")dim dr as DataRow = ds.Tables("contacts").NewRow()dr(1)=txtFirstName.textdr(2)=txtLastName.Textds.Tables("contacts").Rows.Add(dr)objCmd.Update(ds, "contacts")objConn.Close()end sub First Name Last Name
Recommended Answers
Jump to PostYou don't need all those DataSets and DataRows for a simple insert to your database. This looks very long but that's because I have left your code in but commented it out, so you can compare the differences. I have tried to explain with comments all the details. I am …
Jump to PostWell it doesn't like the SQl insert statement, please post your modified code in code tags so I can look at it.
What are the column names in the database for first name and second name?
What other colmns are there ? do they allow null values or …
Jump to PostI changed the column names in the database so that they match with
your ones.Oh well not the conventional method, but that's ok, normally you would change the code to fit the column names. But nevermind as long as they match that's the main thing.
As for the …
All 10 Replies
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.