VS2008+SQL2005+C#: 必须声明标量变量 "@stuname"
using System;using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace ConsoleApplication15
{
class Program
{
static private string GetConnecionString()
{
return "Data Source=.\\SQLEXPRESS;AttachDbFilename=D:\\SQL程序\\SQL数据\\MSSQL\\Data\\student_Data.MDF;Integrated Security=True;Connect Timeout=30;User Instance=True";
}
static void Main(string[] args)
{
string connection = GetConnecionString();
SqlConnection mycon = new SqlConnection(connection);
mycon.Open();
string command = "update s set 姓名=@stuname where 学号= @stuid ";
SqlDataAdapter mydad = new SqlDataAdapter(command, connection);
mydad.UpdateCommand = new SqlCommand(command, mycon );
mydad.UpdateCommand.Parameters.Add("@stuname", SqlDbType.NVarChar, 255, "姓名");
SqlParameter myparameter =mydad.UpdateCommand.Parameters.Add("@stuid", SqlDbType.Float);
myparameter.SourceColumn = "学号";
myparameter.SourceVersion = DataRowVersion.Original;
myparameter.SqlValue = 55;
DataSet mydataset = new DataSet();
mydad.Fill(mydataset, "s");
DataTable mytable = mydataset.Tables["s"];
DataRow myrow = mytable.Rows[1];
myrow["@stuname"] = "王超";
mydad.Update(mydataset, "s");
mycon.Close();
}
}
}
很简单的一个程序,但是总是弹出缺少声明@stuname,请高手帮我看一下撒。多谢多谢! --------------------编程问答-------------------- mydad.UpdateCommand = new SqlCommand(command, mycon );
后面加上姓名和学号变量
mydad.UpdateCommand.Parameters.Add(...);
补充:.NET技术 , C#