本文介绍了cmd.Prepare()不执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨
我有这个代码
int number=reader2.FieldCount;
string insertString="insert into S" + "values(";
for (int i = 1; i <= number; i++)
{
insertString += "@inputs" + i;
if (i != NFIELDS)
{
insertString += ",";
}
else
{
insertString += ")";
}
}
..
...
SqlCommand cmd= new SqlCommand(insertString, conn);
Console.WriteLine(@"Please enter" + reader2.FieldCount + " fields separated by space");
string linefields = Console.ReadLine();
Regex r = new Regex("[ ]+");
string[] fields = r.Split(linefields);
for (int j = 0; j <= reader2.FieldCount-1; j++)/
{
Console.WriteLine(@"Please enter" + fields[j]);
switch (types[j])
{
case "int": cmd.Parameters.Add("@inputs" + j, SqlDbType.Int);
break;
case "float": cmd.Parameters.Add("@inputs" + j, SqlDbType.Float);
break;
default: cmd.Parameters.Add("@inputs" + j, SqlDbType.VarChar);
break;
}
cmd.Parameters[j].Value = fields[j];
}
cmd.Prepare();
cmd.ExecuteNonQuery();
但是cmd.Prepare()无法执行,因此程序会停止.有人可以帮我找我犯错的地方吗?
But the cmd.Prepare() doesn't execute, here the program stops. Can anybody help me please where I make a mistake?
谢谢
推荐答案
string insertString="insert into S" + "values(";
这篇关于cmd.Prepare()不执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!