Programming Journal C#, Java, SQL and to a lesser extent HTML, CSS, XML, and regex. I made this so other programmers could benefit from my experience.

Thursday, September 13, 2007

C# to run stored procedure after parsing text



char[] sSeparators = { ',', ' ' };
string[] sStocks = txtStocks.Text.Split(sSeparators);
SqlConnection conn = new SqlConnection("AttachDbFilename=|DataDirectory|\\ASPNETDB.MDF;User Instance=True;Data Source=.\\SQLEXPRESS;Integrated Security=True;");
System.Data.SqlClient.SqlCommand command = new System.Data.SqlClient.SqlCommand("sproc_aspnet_CreateStockInList", conn);
command.CommandType = System.Data.CommandType.StoredProcedure;
conn.Open();
foreach (string _stock in sStocks)
{
command.Parameters.AddWithValue("@ListId", txtListId.Text.Trim());
command.Parameters.AddWithValue("@Symbol", _stock.Trim());
command.ExecuteNonQuery();
command.Parameters.Clear();
}
conn.Close();

No comments: