fguihen Posted November 3, 2005 Posted November 3, 2005 im sending data from a web form to a web service that saves the data to a database. here is a simplified version of the web form code that creates a new row with the inputted data and passes it to the web service method InsertData. DataSet dataset = new System.Data.DataSet(); DataTable table = new DataTable("Feedback"); table.Columns.Add("Name"); table.Columns.Add("Phone"); table.Columns.Add("comment"); DataRow row = table.NewRow(); row["Name"] = this.TextBox1.Text; row["Phone"] = this.TextBox2.Text; row["comment"] = this.TextBox3.Text; table.Rows.Add(row); localhost.Service1 service = new Feedback.localhost.Service1(); dataset.Tables.Add("Feedback"); here is a basic version of the web service code that is supposed to insert the data into a table: first i open the connection like this: connString = "server=fintanspc; uid=fintan; pwd=nokia3210;database=Test"; conn = new SqlConnection(connString); adapter = new SqlDataAdapter("select*from Feedback",connString); dataSet = new DataSet(); adapter.Fill(dataSet,"Feedback"); dataTable = this.dataSet.Tables[0]; then i try to append the data using this method : public int InsertData(DataSet data) { this.OpenConn(); DataRow row; row = dataTable.NewRow(); row["Name"] = data.Tables["Feedback"].Rows[0].; row["Phone"] = data.Tables["Phone"].Rows[0].ItemArray[1]; row["comment"] = data.Tables["comment"].Rows[0].ItemArray[2]; dataTable.Rows.Add(row); adapter.Update(dataSet,"Feedback"); dataSet.AcceptChanges(); } this does not work, and i have tried many variants of this but i cant get it done. can anyone show me what im doing wrong Quote
Administrators PlausiblyDamp Posted November 4, 2005 Administrators Posted November 4, 2005 In the first code sample you have dataset.Tables.Add("Feedback"); which will create a new datatable in the dataset, are you sure you didn't mean. dataset.Tables.Add(table); instead? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
fguihen Posted November 4, 2005 Author Posted November 4, 2005 yea, thanks. that was one of the issues i had. i had also forgotten to add an insertCommand to my data adapter. works now. thanks for your help 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.