大家好,我正在尝试连接到我的数据库并插入新的患者信息。当我运行我的应用程序时,我得到“无效的参数大小值-1。该值必须大于或等于0。 参数名称:值“请帮忙无法弄清楚参数的设置位置。谢谢
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();
}
}
具有映射属性的My 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 :(得分:0)
下面
[Column( Name = "notes", DbType = "varchar", CanBeNull = true)]
应该是
[Column( Name = "notes", DbType = "varchar(250)", CanBeNull = true)]
某些值(我使用250)