2013-11-25 69 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

相關問題