| 发表于:2007-03-07 15:40:5713楼 得分:0 |
hbxhtlx(平民百姓)老大,在短信息中发不了这么多代码只有在这给您看了 以下是代码.在代码中,我把exid等定义成object类型,将空值写成dbnull.value没用,将exid等定义成string类型,将空值写成 " "也不行,最后报错 "将字符串转成成uniqueidentifier 类型时出错!请老大一定帮帮我!!! private void cmdadd_click(object sender, eventargs e) { string exid, void, trid; if (combobox6.selectedindex == -1) //当没有选择下拉框时 exid = " "; else exid = mytable6.rows[combobox6.selectedindex][ "exid "].tostring(); if (combobox7.selectedindex == -1) void = " "; else void = mytable7.rows[combobox7.selectedindex][ "void "].tostring(); if (combobox8.selectedindex == -1) trd = " "; else trid = mytable8.rows[combobox8.selectedindex][ "trid "].tostring(); if (textbox2.text == " " ) //主要信息必须填写完整,才能保存数据 { messagebox.show( "请输入完整的信息! ", "添加信息 "); return; } else { string strinsert = " insert into table1 (stud_id,stu_code,exid,void,trid ) values ( ' " + modid + " ', ' " + textbox2.text + " ', ' " + exid + " ', ' "+ void + " ', ' " + trid + " ' "); sqlcommand cmd1 = new sqlcommand(strinsert, sqlconnection1); sqlconnection1.open(); cmd1.EXECutenonquery(); sqlconnection1.close(); } } | | |
|