我有使用C#的Windows应用程序,我想将数据存储在本地SQL SERVER数据库以及在线SQL SERVER数据库中。
答案 0 :(得分:0)
你不应该在这里提出这样的问题,但这里有一些东西可以帮助你入门。
using(SqlConnection cnn = new SqlConnection())
{
cnn.ConnectionString="your connection string";
// /*e.g.: */
cnn.ConnectionString = "Server=123.123.123.123,1433;Database=DbName;User id=user;Password=pass;";
using(SqlCommand cmd = new SqlCommand())
{
cmd.CommandType = CommandType.StoredProcedure; //or whatever it is
cmd.ConnectionTimeout = 0; //or however long you want
cmd.Connection = cnn;
cmd.CommandText = "your query";
//cmd.Parameters.AddWithValue("@SP_PARAM", object); if you are calling an SP
cnn.Open();
cmd.ExecuteNonQuery(); //whatever you are executing
cnn.Close();
}
}