在sql server里:
string cmdText = null;
cmdText = "INSERT INTO A(a2,a3) VALUES(@a2,@a3) " +
"SELECT @a1=@@IDENTITY";
QueryParameterCollection qpc = QueryParameterCollection();
qpc.Add("@a2", 1);
qpc.Add("@a3", 2);
qpc.Add("@a1",0);
qpc[2].Direction = ParameterDirection.Output;
bool flag = this.Execute(CommandType.Text, cmdText, qpc);
return flag;
其中 a1为主键,自增长,是没有任何问题的,现在换成mysql出问题了
string cmdText = null;
cmdText = "INSERT INTO A(a2,a3) VALUES(?a2,?a3) " +
"SELECT ?a1=@@IDENTITY";
QueryParameterCollection qpc = QueryParameterCollection();
qpc.Add("?a2", 1);
qpc.Add("?a3", 2);
qpc.Add("?a1",0);
qpc[2].Direction = ParameterDirection.Output;
bool flag = this.Execute(CommandType.Text, cmdText, qpc);
return flag;
语法就有问题了
string cmdText = null;
cmdText = "INSERT INTO A(a2,a3) VALUES(@a2,@a3) " +
"SELECT @a1=@@IDENTITY";
QueryParameterCollection qpc = QueryParameterCollection();
qpc.Add("@a2", 1);
qpc.Add("@a3", 2);
qpc.Add("@a1",0);
qpc[2].Direction = ParameterDirection.Output;
bool flag = this.Execute(CommandType.Text, cmdText, qpc);
return flag;
其中 a1为主键,自增长,是没有任何问题的,现在换成mysql出问题了
string cmdText = null;
cmdText = "INSERT INTO A(a2,a3) VALUES(?a2,?a3) " +
"SELECT ?a1=@@IDENTITY";
QueryParameterCollection qpc = QueryParameterCollection();
qpc.Add("?a2", 1);
qpc.Add("?a3", 2);
qpc.Add("?a1",0);
qpc[2].Direction = ParameterDirection.Output;
bool flag = this.Execute(CommandType.Text, cmdText, qpc);
return flag;
语法就有问题了
试试
试试
SELECT @a1:=@@IDENTITY
or
SELECT @a1:=last_insert_id()