English 中文(简体)
在dotNET中的SQL参数
原标题:
  • 时间:2009-03-22 20:08:19
  •  标签:

这里有一个小问题...

string SQL = @"INSERT INTO [Answers] ([UserID],[QuestionID],[SelectedIndex]) 
  VALUES(@uid,@qid,@sin)";
    SqlParameter[] par = new SqlParameter[] { 
    new SqlParameter("@uid",this.userid),
    new SqlParameter("@qid",this.questionid),
    new SqlParameter("@sin",this.qOptions.SelectedIndex)
    };

this does not work ... Why not? i dunno, but the firs one is bigint in SQL (microsoft 2005) and in dotNET side its an int ... second one is a an SQL uniqueidentifier while its a string in dotNEWT but it works that way i have experience .. third one is an integer in SQL and int in dotNET ... since dotNET does not have any major malfunction, what is my major malfunction? :) thank you sargeant in advance :)))

问题回答

我认为uniqueidentifier应该映射到Guid而不是string。如果你把它改为Guid(只是为了测试),会发生什么?请参阅SqlDbType枚举文档以获取映射列表。

顺便说一句,如果您能说明它不工作的方式,那也会有所帮助。当您报告问题时,这总是一个好主意。它是否抛出异常?

SqlGuid 的隐式操作需要一个 Guid,而不是一个 int。此外,还有针对 String、Byte[] 和 int 的显式构造函数。





相关问题
热门标签