窗体中连接数据库,更新与添加要怎么用存储过程?
我是做好界面,将sqldataadapter控件拖到窗体上,使用生成新的存储过程命令分别是
bkSelectcomm
bkDeletecomm
bkUpdaetcomm
bkInsertcomm
具体在以下的程序中应该怎么用到?
下面我做的程序只可以添加新记录,但是却不能更改,说找不到update命令。
各位大哥,小弟初学C#,用的是VS2005,请帮帮我啊~
public partial class Book : Form
{
public Book()
{
InitializeComponent();
sqlConnection1.Open();
sqlDataAdapter1.Fill(bookDS1,"bkSelectcomm");
CurrentPosition();
}
private void CurrentPosition()
{
int currentPostion, ctr;
ctr = this.BindingContext[bookDS1, "bkSelectcomm"].Count;
if (ctr == 0)
{
txtPosition.Text = "目前没有记录";
}
else
{
currentPostion = this.BindingContext[bookDS1, "bkSelectcomm"].Position + 1;
txtPosition.Text = currentPostion.ToString() + "of" + ctr.ToString();
}
}
private void btnExit_Click(object sender, EventArgs e)
{
this.Close();
}
private void btnBack_Click(object sender, EventArgs e)
{
try
{
btnBack.BindingContext[bookDS1, "bkSelectcomm"].Position -= 1;
CurrentPosition();
}
catch (System.Exception eBack)
{
System.Windows.Forms.MessageBox.Show(eBack.ToString());
}
}
private void btnNext_Click(object sender, EventArgs e)
{
try
{
btnNext.BindingContext[bookDS1, "bkSelectcomm"].Position += 1;
CurrentPosition();
}
catch (System.Exception eNext)
{
System.Windows.Forms.MessageBox.Show(eNext.ToString());
}
}
private void btnAdd_Click(object sender, EventArgs e)
{
try
{
this.BindingContext[bookDS1, "bkSelectcomm"].EndCurrentEdit();
this.BindingContext[bookDS1, "bkSelectcomm"].AddNew();
}
catch (System.Exception eEndEdit)
{
System.Windows.Forms.MessageBox.Show(eEndEdit.Message);
}
textBox2.Enabled = true;
textBox3.Enabled = true;
textBox4.Enabled = true;
textBox5.Enabled = true;
textBox6.Enabled = true;
textBox7.Enabled = true;
textBox8.Enabled = true;
textBox9.Enabled = true;
//int i=this.BindingContext[bookDS1, "bkSelectcomm"].Position;
//textBox1.Text = bookDS1.Tables[0].Rows[i]["BookID"].ToString();
textBox2.Text = "";
textBox3.Text = "";
textBox4.Text = "";
textBox5.Text = "";
textBox6.Text = "";
textBox7.Text = "";
textBox8.Text = "";
textBox9.Text = "";
//textBox1.Text = bookDS1.Tables[0].Rows[this.BindingContext[bookDS1, "bkSelectcomm"].Position][0].ToString();
CurrentPosition();
}
private void btnEdit_Click(object sender, EventArgs e)
{
textBox2.Enabled = true;
textBox3.Enabled = true;
textBox4.Enabled = true;
textBox6.Enabled = true;
textBox7.Enabled = true;
textBox8.Enabled = true;
textBox9.Enabled = true;
bookDS1.Tables[0].Rows[this.BindingContext[bookDS1, "bkSelectcomm"].Position][0] = textBox2.Text;
}
private void btnDelete_Click(object sender, EventArgs e)
{
try
{
this.BindingContext[bookDS1,"bkSelectcomm"].RemoveAt(this.BindingContext[bookDS1,"bkSelectcomm"].Position);
CurrentPosition();
}
catch (System.Exception eRemove)
{
System.Windows.Forms.MessageBox.Show(eRemove.ToString());
}
}
private void btnCancel_Click(object sender, EventArgs e)
{
bookDS1.Clear();
sqlDataAdapter1.Fill(bookDS1,"bkSelectcomm");
CurrentPosition();
}
private void btnConfirm_Click(object sender, EventArgs e)
{
sqlDataAdapter1.Update(bookDS1,"bkSelectcomm");
MessageBox.Show("Update");
}
}