给你个参考://==============================================================================
//功能 : 执行指定的SQL语句
//参数 : 要执行的Sql语句
//返回值 : 1:执行成功;0:执行失败
//==============================================================================
public int ExeSql(string Sql)
{
SqlConnection myConnection = new SqlConnection(this.ConnectionString);
SqlCommand myCommand=new SqlCommand(Sql,myConnection);
try
{
myConnection.Open();
myCommand.ExecuteNonQuery();
myCommand.Dispose();
myConnection.Close();
return 1;
}
catch(SqlException e)
{
errMsg = "";
errMsg += e.Message;
myConnection.Close();
return 0;
}
}再加上你的SQL语句就可以了。
//功能 : 执行指定的SQL语句
//参数 : 要执行的Sql语句
//返回值 : 1:执行成功;0:执行失败
//==============================================================================
public int ExeSql(string Sql)
{
SqlConnection myConnection = new SqlConnection(this.ConnectionString);
SqlCommand myCommand=new SqlCommand(Sql,myConnection);
try
{
myConnection.Open();
myCommand.ExecuteNonQuery();
myCommand.Dispose();
myConnection.Close();
return 1;
}
catch(SqlException e)
{
errMsg = "";
errMsg += e.Message;
myConnection.Close();
return 0;
}
}再加上你的SQL语句就可以了。
{
try
{
conn.Open(); // 向表中添加记录
string strInsert = "insert into attendINFO values(@usrID, @timeCome, @timeGo)";
SqlCommand storeCommand = new SqlCommand(strInsert, conn);
storeCommand.Parameters.Add("@usrID", usrID));
storeCommand.Parameters.Add("@timeCome", DateTime.Parse("2003/3/21/3/30"));
storeCommand.Parameters.Add("@timeGo",DateTime.Parse("2003/3/21/4/30")));
storeCommand.ExecuteNonQuery();
conn.Close(); }
catch(SqlException ae)
{
System.Console.WriteLine(ae.Message.ToString());
}
}