2013-11-25 48 views
0

大家好,我正尝试连接到我的数据库并插入新的患者信息。当我运行我的应用程序时,我得到“无效的参数大小值-1,该值必须大于或等于0. 参数名称:值”请帮助找不到设置参数的位置。由于无效的参数大小值-1

using System.Collections.Generic; 
    using System.Data.Linq; 
    using System.Windows.Forms; 
    using iAnywhere.Data.SQLAnywhere; 

    namespace...  
    public class PatientService 
     { 
     private const string ConnectionString = "Dsn=SQL Anywhere 
            10;uid=DBA;PWD=sql;databasefile='C:\\Users\\Public\\Documents\\SQL Anywhere 10\\Samples\\Training1.db';"; 

     public void CreatePatientInfo(Patient patient) 
      { 
      DataContext patientDataContext = new DataContext(Conn); 

      Conn.Open(); 

      Table<Patient> patientsTableList = patientDataContext.GetTable<Patient>(); 

      patientsTableList.InsertOnSubmit(patient); 


      patientDataContext.SubmitChanges(); 
      Conn.Close(); 
      } 
     } 

我与测绘Patient类属性

using System.Data.Linq.Mapping; 

    namespace ... 
    { 
    [Table(Name = "patient")] 
    public class Patient 
    { 
    public Patient() 
    { 
    } 

    public Patient(string patientId, string firstName, string lastName, string address, string city, string state, 
     string zipcode, string phoneNumber, string notes, int classificationId) 
    { 
     PatientId = patientId; 
     FirstName = firstName; 
     LastName = lastName; 
     Address = address; 
     City = city; 
     State = state; 
     Zipcode = zipcode; 
     PhoneNumber = phoneNumber; 
     Notes = notes; 
     ClassificationID = classificationId; 
    } 

    [Column(Name = "patient_id", DbType = "char(5) NOT NULL", CanBeNull = false, 
     IsPrimaryKey = true)] 
    public string PatientId { get; set; } 

    [Column(Name = "first_name", DbType = "char(40)", CanBeNull = false)] 
    public string FirstName { get; set; } 

    [Column(Name = "lastname", DbType = "char(40)", CanBeNull = false)] 
    public string LastName { get; set; } 

    [Column(Name = "address", DbType = "char(40)", CanBeNull = true)] 
    public string Address { get; set; } 

    [Column(Name = "city", DbType = "char(40)", CanBeNull = true)] 
    public string City { get; set; } 

    [Column(Name = "state", DbType = "char(2)", CanBeNull = true)] 
    public string State { get; set; } 

    [Column(Name = "zipcode", DbType = "char(9)", CanBeNull = true)] 
    public string Zipcode { get; set; } 

    [Column(Name = "phone", DbType = "char(10)", CanBeNull = true)] 
    public string PhoneNumber { get; set; } 

    [Column(Name = "notes", DbType = "varchar", CanBeNull = true)] 
    public string Notes { get; set; } 

    [Column(Name = "classification_id", DbType = "int", CanBeNull = true)] 
    public int ClassificationID { get; set; } 
} 

}

+0

我希望您的连接字符串字段不是像这样声明的... – terrybozzio

+0

您是否检查过“患者”对象中的所有值? – Poornima

+0

是的,我将它与数据库中的值进行了匹配。 – Alvie212

回答

0

这里

[Column(Name = "notes", DbType = "varchar", CanBeNull = true)] 

应该

[Column(Name = "notes", DbType = "varchar(250)", CanBeNull = true)] 

对于某些值(我使用了250)

+0

感谢您的回答,但它仍然抛出相同的例外 – Alvie212

相关问题