读书人

OleDb更新Access数据库的有关问题

发布时间: 2012-02-03 22:02:47 作者: rapoo

OleDb更新Access数据库的问题
这段代码是更新Access数据库的,中有两个问题,让我抓狂了一天了

public void UpdateExpNote(IExpNote iExpNote)
{
string SQLUpdateExpNote = "UPDATE ExpNote SET IsPublished = @IsPublished, ProgramID = @ProgramID, NoteAuthor = @NoteAuthor ,NoteName = @NoteName WHERE NoteID = @NoteID; ";

OleDbConnection conn = null;
conn = GetConnection();

OleDbCommand cmd = new OleDbCommand(SQLUpdateExpNote, conn);

cmd.Parameters.Add( "@ExpNoteId ", OleDbType.Integer).Value = iExpNote.ExpNoteID;
cmd.Parameters.Add( "@IsPublished ", OleDbType.Boolean).Value = iExpNote.IsPublished;
cmd.Parameters.Add( "@NoteAuthor ", OleDbType.VarWChar, 50).Value = iExpNote.ExpNoteAuthor;
cmd.Parameters.Add( "@ProgramID ", OleDbType.Integer).Value = iExpNote.ProgramID;
cmd.Parameters.Add( "@NoteName ", OleDbType.VarWChar, 100).Value = iExpNote.ExpNoteName;

conn.Open();
int val = cmd.ExecuteNonQuery();
conn.Close();
}

第一是不管我的iExpNote.IsPublished是true还是false,Update以后IsPublished字段的值都变成了1,(IsPublished在Access中设为 是/否 类型)

第二是NoteName无论怎么样都不更新,即使别的字段都更新了它还是不变,死了不变,急死人了。

有谁能帮帮我的,多谢了

[解决办法]
在SQLSERVER中使用@参数可以,在ACCESS中应该是使用OLEDB,应该是update tablename set field1=?,field2=? where ID=?
[解决办法]
忘记了。好像是filed
[解决办法]
1.直接用字符串的true/false或yes/no试试
[解决办法]
1、你试试在“int val = cmd.ExecuteNonQuery();”中去掉“int val = ”
2、你的NoteAuthor和NoteName用的应该是一种表示方法,如果前者能更新后者不能,那绝对是人的问题了。我晕~~怎么可能哦

读书人网 >C#

热点推荐