如何使用C#在访问表中设置默认值 [英] how to set default value in access table using C#
本文介绍了如何使用C#在访问表中设置默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用C#在访问表中设置默认值
我想添加默认值="
how to set default value in access table using C#
I want add default value=""
Catalog cat = new Catalog();
string strCreateDB = "";
strCreateDB += "Provider=Microsoft.Jet.OLEDB.4.0;";
strCreateDB += "Data Source=" + strPath + ";";
strCreateDB += "Jet OLEDB:Engine Type=5";
cat.Create(strCreateDB);
Table tblPhases = new Table();
tblPhases.Name = "tblPhases";
ADOX.Column objCol = new Column();
objCol.Name = "PhaseID";
tblPhases.Columns.Append(objCol, ADOX.DataTypeEnum.adInteger);
tblPhases.Keys.Append("PhaseIDPrimaryKey", KeyTypeEnum.adKeyPrimary, objCol);
tblPhases.Columns.Append("PhaseCaption", DataTypeEnum.adVarWChar, 255);
tblPhases.Columns.Append("PhaseDesc", DataTypeEnum.adVarWChar, 255);
cat.Tables.Append(tblPhases);
推荐答案
Access数据库字段的默认值由数据库设置为 NonExistant Value 不等于"或C#为null.它是 DBNull.Value
另一方面,如果要在数据集中设置默认值,请转到数据集设计器并选择所需表的所需列.然后,使用 DataColumn 的 DefaultValue 属性,可以在属性窗口中将字段类型为字符串的默认值设置为".
The default value of Access database field is set by database to NonExistant Value which is not equal to "" or null of C#. It is DBNull.Value
On the other hand if you want to set a default value in the dataset, go to dataset designer and select the required column of the required table. Then from the properties window you can set the default value to "" if the field type is string, using the DefaultValue property of the DataColumn.
这篇关于如何使用C#在访问表中设置默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文