回 帖 发 新 帖 刷新版面

主题:在VC#下建立数据表的问题,加分

如果大家不想看我的程序,就请只看下划线的地方
...........
  SqlConnection myConnection;
  myConnection=new SqlConnection("server=(local);database=model;Trusted_Connection=yes");
  string creatCmd = "create table @youpig (number char(10) not null primary key,more int)";
  SqlCommand myCommand = new SqlCommand(creatCmd,myConnection);
  [u]myCommand.Parameters.Add(new SqlParameter("@youpig",SqlDbType.NVarChar,10));
  myCommand.Parameters["@youpig"].Value=this.textBox1.Text;[/u]
  myCommand.Connection.Open();
  try
  {
    myCommand.ExecuteNonQuery();
  }
  catch(SqlException ex)
  {
    MessageBox.Show("建立表错误");
  }
  myCommand.Connection.Close();
..........
这个程序就只有下划线的地方有错误,请教高手应该怎么该,使它运行成功。谢谢

回复列表 (共1个回复)

沙发

myCommand.Parameters.Add(new SqlParameter("youpig",SqlDbType.NVarChar,10));
  myCommand.Parameters["youpig"].Value=this.textBox1.Text;
试试

我来回复

您尚未登录,请登录后再回复。点此登录或注册