我创建了一个mdb数据库并将表链接到mysql。
尝试插入时出现以下错误:
“fotoid”不能为空
堆栈跟踪错误:
源:system.data堆栈跟踪:system.data.datacolumn.checknullable(datarow row)system.data.datacolumn.checkcolumnconstraint(datarow row,datarowaction action)system.data.datatable.RaiseRowChange(datarowchangeeventargs args,datarow erow,datarowaction eaction,boolean fireevent)system.data.datatable.setnewrecordworker(datarow row,int32 proposedrecord,datarowaction action,boolean isinmerge,int32 position,boolean fireevent,exception&DeferreException)system.data.datatable.insertrow(datarow行,int64 proposedid,int32 pos,boolean fireevent)system.data.datarowcollection.add(datarow行)。。。
我的c代码如下:
query = "SELECT * FROM SFoto where SID="+sid;
cmd = new OleDbCommand(query, conn);
OleDbDataAdapter t2DataAdapter = new OleDbDataAdapter(cmd);
OleDbCommandBuilder t2Command = new OleDbCommandBuilder(t2DataAdapter);
t2DataAdapter.FillSchema(ds, SchemaType.Source, "SFoto");
row2 = ds.Tables["SFoto"].NewRow();
row2["FotoName"] = Path.GetFileName(foldername).ToString();
row2["FotoNote"] = megjtxt.Text;
row2["SID"] = sid;
row2["FotoDefault"] = "true";
row2["InsertDate"] = utils.Settings.GetInsModDate() ;
row2["InsertedBy"] = utils.Settings.LoggedInUser;
ds.Tables["SFoto"].Rows.Add(row2);
t2DataAdapter.Update(ds, "SFoto");
mysql中的表:
CREATE TABLE `sfoto` (
`FotoID` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`FotoName` longtext,
`FotoNote` longtext,
`SID` int(11) NOT NULL,
`FotoDefault` varchar(255) DEFAULT NULL,
`InsertDate` varchar(255) DEFAULT NULL,
`ModifyDate` varchar(255) DEFAULT NULL,
`InsertedBy` varchar(255) DEFAULT NULL,
`ModifiedBy` varchar(255) DEFAULT NULL,
KEY `SID` (`SID`),
KEY `FotoID` (`FotoID`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8
我也制造了一个触发器,但没用:
CREATE TRIGGER `sfoto_before_trigger` BEFORE INSERT ON `sfoto`
FOR EACH ROW BEGIN
SET SESSION sql_mode='';
SELECT `auto_increment` INTO @NEXTID FROM INFORMATION_SCHEMA.TABLES
WHERE table_name = 'sfoto';
INSERT INTO sirfoto (`FotoID`,`FotoName`,`FotoNote`,`SID`,`FotoDefault`,`InsertDate`,`ModifyDate`,`InsertedBy`,`ModifiedBy`)
VALUES(NULL,NEW.FotoName,NEW.FotoNote,NEW.SID,NEW.FotoDefault,NEW.InsertDate,NEW.ModifyDate,NEW.InsertedBy,NEW.ModifiedBy);
/* SET NEW.`FotoID` = @NEXTID;*/
END
编辑:我跟随这个视频创建链接表到mysql:linked table
暂无答案!
目前还没有任何答案,快来回答吧!