string ConnectionString = "server=.;database=pubs;uid=as;pwd=sa";//连接字符串
try
{
SqlConnection con = new SqlConnection(ConnectionString);//声明连接对象
con.Open();//打开连接
SqlCommand cmd = new SqlCommand("insert into tableName values('"+张三+"','"+男+"')",con);
cmd.ExecuteNonQuery();//执行 向数据库插入的Sql语句
}
catch(Exception ex)
{
throw new Exception("错作错误"+ex.Message);
}