MultiLineTextbox - work with the data to SQL
MultiLineTextbox - work with the data to SQL
(OP)
Hi All,
I have a winform with a multi-line textbox- the user pastes in 1 column of data - example firstname - therefore there could be 10 names in a row.
I would like to capture this data and pass it to a sql stored procedure.
I have managed to go about it with code below - but this runs the procedure for every firstname there is - I was wondering if there is a better way of doing this - like for instance getting the values and passing them all in one go like : in ('firstname1','firstname2','firstname3')etc, but I have looked and looked and I can't figure out how to construct this from a multilined text box. Or maybe there is a completely better way to get the user to put the data through?
Any information to guide me in the right direction will be appreciated.
Many thanks
Michael
I have a winform with a multi-line textbox- the user pastes in 1 column of data - example firstname - therefore there could be 10 names in a row.
I would like to capture this data and pass it to a sql stored procedure.
I have managed to go about it with code below - but this runs the procedure for every firstname there is - I was wondering if there is a better way of doing this - like for instance getting the values and passing them all in one go like : in ('firstname1','firstname2','firstname3')etc, but I have looked and looked and I can't figure out how to construct this from a multilined text box. Or maybe there is a completely better way to get the user to put the data through?
Any information to guide me in the right direction will be appreciated.
Many thanks
Michael
CODE --> sharp
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["DBname"].ConnectionString.ToString()); con.Open(); SqlCommand cmd = new SqlCommand(); cmd.Connection = con; cmd.CommandText = "proc_updatefirstname "; //this is the stored procedure to execute cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(new SqlParameter("@firstname ", SqlDbType.NVarChar, 50)); string[] textBoxLines = textBox4.Lines; foreach (string line in textBoxLines) { cmd.Parameters["@firstname "].Value = line; cmd.ExecuteNonQuery(); } con.Close();
RE: MultiLineTextbox - work with the data to SQL
Hope this helps.
RE: MultiLineTextbox - work with the data to SQL