trying to save data from webForm via a web service.need help

fguihen

Junior Contributor
Joined
Nov 10, 2003
Messages
248
Location
Eire
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.

Code:
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:
Code:
			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 :
Code:
		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
 
In the first code sample you have
C#:
dataset.Tables.Add("Feedback");
which will create a new datatable in the dataset, are you sure you didn't mean.
C#:
dataset.Tables.Add(table);
instead?
 
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
 
Back
Top