在Listview中添加数据(Access)的方法,但执行完da.Update(ds);后就转去了Catch,不知为什么?
public static int Insert(string tableName,string[] data)
{
string ole = "select * from "+tableName;
OleDbDataAdapter da = new OleDbDataAdapter(ole,con);
try
{
if(con.State != ConnectionState.Open)
{
con.Open();
}
OleDbCommandBuilder cb = new OleDbCommandBuilder(da);
DataSet ds = new DataSet();
da.Fill(ds);
DataRow dr = ds.Tables[0].NewRow();
for(int i=0;i<=data.Length-1;i++)
{
dr[i+1]=data[i];
}
MessageBox.Show("a","b");
ds.Tables[0].Rows.Add(dr);
da.Update(ds);
return 0;
} catch(Exception ex)

{   ... ...

解决方案 »

  1.   

    不能直接用da.Update(ds);这个更新吧
      

  2.   

    追加
    From中的添加如下:private void btn_Add_Click(object sender, System.EventArgs e)
    {
    string Add_Date = dateTimePicker1.Text;
    string Add_Data = txt_ZYD_Data.Text;
    string Add_Eligibillity = txt_ZYD_Eligibillity.SelectedItem.ToString();
    string[] Add = new string[]{Add_Date,Add_Data,Add_Eligibillity};
    int i=Data.Data.Insert("TZYD",Add);

    if(i==0)
    {
    btn_List_Click(null,null); }
    else
    {
    MessageBox.Show("不成功!");
                }
    }执行后就直接跳到“不成功!”了。