我正在使用向导创建一个断开连接的数据集项目,但是,它允许我从表中更新和删除数据,但它不允许我插入新数据行并且仍然给我消息框“SUCCESS”!!!!
namespace Disconnected_Database_by_Wizard
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
SqlConnection myConnection = new SqlConnection();
SqlDataAdapter myAdapter = null;
private void Form1_Load(object sender, EventArgs e)
{
myConnection.ConnectionString = "Server=CompileMe;Database=MyDataBase;Integrated Security = True";
myAdapter = new SqlDataAdapter("Select * from MyList", myConnection);
myConnection.Open();
myAdapter.Fill(dataSet1,"MyList");
SqlCommandBuilder myCommandBuilder = new SqlCommandBuilder(myAdapter);
myAdapter.InsertCommand = myCommandBuilder.GetInsertCommand();
myAdapter.UpdateCommand = myCommandBuilder.GetUpdateCommand();
myAdapter.InsertCommand = myCommandBuilder.GetDeleteCommand();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
myAdapter.Update(dataSet1 ,"Mylist");
MessageBox.Show("Success");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
myConnection.Close();
}
}
}
}
提前致谢 :)