读书人

数据集插入记录返回0请高手帮助解决

发布时间: 2012-02-22 19:36:56 作者: rapoo

数据集插入记录返回0,请高手帮助
我是WINFORM ACCESS数据库 没有提示任何错误,只是返回UPDATA返回0
代码如下

string cmdselect = "SELECT * FROM [base] where 0> 1 ";
string myConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " + System.Windows.Forms.Application.StartupPath + "\\database\\esenge.mdb " + ";User ID=admin;Jet OLEDB:Database Password=lq~b819_531~by ";
OleDbConnection conn = new OleDbConnection(myConnectionString);

conn.Open();
OleDbCommand command = conn.CreateCommand();
command.CommandText = cmdselect; //SQL命令赋值 ,以获得结构
//command.CommandType = CommandType.TableDirect;

OleDbDataAdapter adapter = new OleDbDataAdapter(command);


//adapter.SelectCommand = cmdselect;
DataSet ds = new DataSet();
adapter.Fill(ds, cmdselect);
adapter.TableMappings.Add( "base ", "base ");
DataRow dr = ds.Tables[0].NewRow(); ;
//ds.Clear();//清除该表记录,只保留结构



//DataRow dr = ds.Tables[0].NewRow();//增加新的一行;

dr[0] = nform0.Text;


dr[1] = nform1.Text;
dr[2] = nform2.Text;
dr[3] = nform3.Text;
dr[4] = nform4.Text;
dr[5] = DateTime.Parse(nform5.Text);
dr[6] = nform6.Text;
dr[7] = nform7.Text;
dr[8] = nform8.Text;
dr[9] = nform9.Text;
dr[10] = nform10.Text;
dr[11] = nform11.Text;
dr[12] = nform12.Text;
dr[13] = nform13.Text;
if (nform14.Text == " ") { nform14.Text = "510000 "; }
dr[14] = Convert.ToUInt32(nform14.Text);

dr[15] = nform15.Text;
dr[16] = nform16.Text;
dr[17] = nform17.Text;
dr[18] = nform18.Text;
dr[19] = nform19.Text;
dr[20] = nform20.Text;
dr[21] = nform21.Text;
dr[22] = DateTime.Parse(nform22.Text);


dr[23] = nform23.Text;
dr[24] = nform24.Text;
dr[25] = nform25.Text;
if (nform26.Text == " ")
{
int a = 0;
dr[26] = a;
}
else {
dr[26] = Convert.ToUInt16(nform26.Text);
}

dr[27] =DateTime.Parse(nform27.Text);
dr[28] = nform28.Text;
dr[29] = nform29.Text;
dr[30] = nform30.Value;
dr[31] = nform31.Text;
dr[32] = nform32.Value;
dr[33] = nform33.Value;
dr[34] = nform34.Text;
dr[35] = nform35.Text;
dr[36] = lizhi;
dr[37] = nform37.Value;
if (nform38.Text == " ")
{
dr[38] = 0;


}
else { dr[38] = Convert.ToUInt16(nform38.Text); }

if (nform39.Text == " ") { dr[ "工资 "] = 0; } else { dr[ "工资 "] = Convert.ToDecimal(nform39.Text); }

dr[40] = nform40.Text;

//adapter.UpdateCommand = mycb.GetUpdateCommand();
OleDbCommandBuilder mycb = new OleDbCommandBuilder(adapter);


ds.Tables[0].Rows.Add(dr);//这行增加一行
adapter.Fill(ds);


MessageBox.Show(ds.Tables[0].Rows.Count.ToString() + adapter.InsertCommand.ToString());
try
{

if (adapter.Update(ds, "base ") > = 1)
{
MessageBox.Show( "成功 ");
}
else
{
MessageBox.Show( "没有成功(: ");
}
}
catch( Exception err )


{
MessageBox.Show(err.Message);
}
finally
{
//ds.Dispose();
//adapter.Dispose();
conn.Close();//这里关闭数据库了
}


[解决办法]
我帮你

读书人网 >C#

热点推荐