public static DataTable ExecuteSQL(string sql, Dictionary//insert a tag recordparameters)
{
DataTable dt = new DataTable("DataTable");
using (SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["localConnectionString"].ConnectionString))
{
myConnection.Open();
SqlCommand mySqlCommand = new SqlCommand(sql, myConnection);
if (parameters != null)
{
foreach (KeyValuePairp in parameters)
{
mySqlCommand.Parameters.AddWithValue(p.Key, p.Value);
}
}
using (SqlDataReader datareader = mySqlCommand.ExecuteReader())
{
dt.Load(datareader);
}
}
return dt;
}
Dictionary
param.Add("@TagName", txtTagName.Text);
ExecuteSQL("INSERT TOP (200) INTO Tag(TagName) VALUES (@TagName)", param);