i am doing a project on web service and window form
basically i meet some problem and not sure how to solve
-
i want to get the data in every row in ColA of datagridview and inside into the data base through web service, to get something like this row1;row2;row3;row4……so i did a for loop but at underline with the nominal which i highlight in bold
private void push_Click(object sender, EventArgs e) { string nominal; for (int i = 0; i < DGV.Rows.Count; i++) { nominal = Convert.ToString(DGV.Rows[i].Cells[1].Value); } WSBrand insertInto = new WSBrand(); insertInto.Insert(**nominal**) }
this is my insert method
[WebMethod]
public DataSet Insert(String BrandName)
{
SqlCommand dbCommand = new SqlCommand();
dbCommand.CommandText = "INSERT INTO Brand (BrandName)VALUES (@BrandName)";
dbCommand.Connection = conn;
da = new SqlDataAdapter();
da.SelectCommand = dbCommand;
dbCommand.Parameters.AddWithValue("@BrandName", BrandName);
DataSet ds = new DataSet();
da.Fill(ds);
return ds;
}
In Your WSBrand Class:
The problem is that nominal is being overwritten in every iteration of the for loop. If you create a List of strings that contain all the values of the DGV then it will be easier to access them all in your WSBrand class.
EDIT: When you are executing the INSERT Statement the only thing that will be returned is the number of rows affected. To get all the data back you must execute a SELECT * FROM Brands query and that will enable you to fill your Dataset with data!
Final EDIT: This should work hopefully. I have changed both the push_Click method and the Insert Method. If there are any syntax errors you will have to work these out as I done this in notepad. Good Luck