+ -
当前位置:首页 → 问答吧 → 新手急求 在线等

新手急求 在线等

时间:2011-12-21

来源:互联网

SqlConnection conn = new SqlConnection();
  conn.ConnectionString = "Data Source=V50JJE4\\SQLEXPRESS;Initial Catalog=MyBlog;User ID=sa;Password=ko";
  conn.Open();
   
  SqlDataAdapter da = new SqlDataAdapter();
  try
  {
  SqlCommand cmd = new SqlCommand();
  cmd.CommandType = CommandType.StoredProcedure;
  cmd.CommandText = "InsertArtical";
  cmd.Parameters.Add("@Artical_ID", System.Data.SqlDbType.Int, 32).Value = TextBox3.Text;
  cmd.Parameters.Add("@Artical_Title", System.Data.SqlDbType.NVarChar, 50).Value = TextBox1.Text;
  cmd.Parameters.Add("@Artical_Content", System.Data.SqlDbType.NVarChar, 50) .Value = TextBox2.Text;




  int se = cmd.ExecuteNonQuery(); 出先错误:Connection属性尚未初始化

作者: yihouxiaoguai1   发布时间: 2011-12-21

SqlCommand cmd = new SqlCommand(conn);

作者: kkxxllasasas   发布时间: 2011-12-21

SqlCommand command = new SqlCommand(
  queryString, connection);

作者: bastenf   发布时间: 2011-12-21

引用 2 楼 bastenf 的回复:
SqlCommand command = new SqlCommand(
queryString, connection);


+1
你sql语句和链接语句都没有,怎么执行sql?

作者: happy09li   发布时间: 2011-12-21

cmd.Connection = conn;

作者: FENG03   发布时间: 2011-12-21

SqlConnection conn = new SqlConnection();
  conn.ConnectionString = "Data Source=V50JJE4\\SQLEXPRESS;Initial Catalog=MyBlog;User ID=sa;Password=ko";
  conn.Open();
   
  SqlDataAdapter da = new SqlDataAdapter();
  try
  {
  SqlCommand cmd = new SqlCommand();
  cmd.Connection = conn;
  cmd.CommandType = CommandType.StoredProcedure;
  cmd.CommandText = "InsertArtical";
  cmd.Parameters.Add("@Artical_ID", System.Data.SqlDbType.Int, 32).Value = TextBox3.Text;
  cmd.Parameters.Add("@Artical_Title", System.Data.SqlDbType.NVarChar, 50).Value = TextBox1.Text;
  cmd.Parameters.Add("@Artical_Content", System.Data.SqlDbType.NVarChar, 50) .Value = TextBox2.Text;

作者: xiaozhi797   发布时间: 2011-12-21

引用 2 楼 bastenf 的回复:
SqlCommand command = new SqlCommand(
queryString, connection);


+1

作者: liuleiyu121520   发布时间: 2011-12-21

相关阅读 更多

热门下载

更多