“字段将不能置于记录中” 错误一解: dbf文件 多个(32)个长字段(200),创建时即报错。
create table [YHJJP3.dbf]([GYH] text(200),[NBTXHM] text(200),[xtwpdm] text(200),[xsyhsl] int,[xsyhje] text(200),[xtwldm] text(200),[xsxqrq]
datetime,[xtwpmc] text(200),[xtwpmc1] text(200),[xtwpks] text(200),[xtpzgg] int,[xtysmc] text(200),[COLOR] text(200),[PSIZE] text(200),[xtxhxh] int,
[CFB] text(200),[CFB1] text(200),[CFB2] text(200),[CFB_REF] text(200),[ypypdm] text(200),[dhpshh] int,[xtpsdm] text(200),[dhhthm] int,[xtgydm] text(200),
[dhgs] text(200),[wpzbdm] int,[xghjg] text(200),[xxsdj] int,[JG] text(200),[NUM] int,[xtxhlx] int,[dyhthm] text(200),[wpzxbz] text(200),[wpaqlb] text(200),
[wpdpgb] text(200),[wpdpjy] text(200),[wpdpdj] text(200),[wpsxlb200] text(200),[xtwpjq] text(200),[xttxhm] text(200),[xtspbm] text(200),[xsdhlx] int)
private void button1_Click(object sender, EventArgs e)
{
MyDbfFuct mydbffile = new MyDbfFuct();
FolderBrowserDialog fbd = new FolderBrowserDialog();
fbd.Description = "选择dBase IV文件保存的文件夹";
fbd.SelectedPath = System.Environment.CurrentDirectory;
fbd.ShowNewFolderButton = true;
if (fbd.ShowDialog() == DialogResult.OK)
{
if (mydbffile.Create(fbd.SelectedPath))
{
MessageBox.Show("ok");
}
}
}
public bool Create(string filename)
{
bool r = false;
string outconnstring = string.Format("Provider = Microsoft.Jet.OLEDB.4.0 ;Data Source ={0};Extended Properties=dBASE IV;", filename);//+ "YHJJP1.dbf"
OleDbConnection outConn = new OleDbConnection(outconnstring);
OleDbCommand dc = outConn.CreateCommand();
try
{
outConn.Open();
dc.CommandType = CommandType.Text;
dc.CommandText = "create table [YHJJP3.dbf]([GYH] text(20),[NBTXHM] text(20),[xtwpdm] text(20),[xsyhsl] int,[xsyhje] text(20),[xtwldm] text(20),[xsxqrq] datetime,[xtwpmc] text(20),[xtwpmc1] text(20),[xtwpks] text(20),[xtpzgg] int,[xtysmc] text(20),[COLOR] text(20),[PSIZE] text(20),[xtxhxh] int,[CFB] text(20),[CFB1] text(20),[CFB2] text(20),[CFB_REF] text(20),[ypypdm] text(20),[dhpshh] int,[xtpsdm] text(20),[dhhthm] int,[xtgydm] text(20),[dhgs] text(20),[wpzbdm] int,[xghjg] text(20),[xxsdj] int,[JG] text(20),[NUM] int,[xtxhlx] int,[dyhthm] text(20),[wpzxbz] text(20),[wpaqlb] text(20),[wpdpgb] text(20),[wpdpjy] text(20),[wpdpdj] text(20),[wpsxlb20] text(20),[xtwpjq] text(20),[xttxhm] text(20),[xtspbm] text(20),[xsdhlx] int)";//CREATE TABLE table1 (自动编号 int,名称 Char(5),工资 Double)
//这里用最上面的脚本就报错,改成直接上面的就不报错。
dc.ExecuteNonQuery();
r = true;
}
catch (Exception c)
{
_ErrInfo = c.Message;
}
finally
{
dc.Dispose();
if (outConn.State == System.Data.ConnectionState.Open)
outConn.Close();
outConn.Dispose();
}
return r;
}