PDA

View Full Version : تو DataGrideبه روز و درج نمیکنه



Blackk_lightt
چهارشنبه 21 فروردین 1387, 08:41 صبح
سلام.
این کد مشگلش چیه ؟
فقط حذف رو تو بانک ذخیره میکنه.
واسه بقیش خطا می ده :عصبانی++::عصبانی++::عصبانی++:

publicpartialclassForm1 : Form
{
privateDataSet ObjDataSet = newDataSet();
privateSqlConnection SqlConnection1 = newSqlConnection();
privateSqlDataAdapter SqlDataAdapter1 = newSqlDataAdapter();
public Form1()
{
InitializeComponent();
this.SqlConnection1.ConnectionString = "Data Source= . ;Initial Catalog=Dad;Integrated Security=True";
this.SqlDataAdapter1.SelectCommand = newSqlCommand("SELECT * FROM Register", this.SqlConnection1);
this.SqlDataAdapter1.Fill(this.ObjDataSet, "Re");
this.dataGridView1.DataSource = ObjDataSet;
this.dataGridView1.DataMember = "Re";

//Initialize UPDATE Command.
this.SqlDataAdapter1.UpdateCommand = newSqlCommand("UPDATE Register SET Fname = @FName, LName = @LName WHERE ID = @id", this.SqlConnection1);
this.SqlDataAdapter1.UpdateCommand.Parameters.AddW ithValue("@FName", typeof(string)).SourceColumn = "Field1";
this.SqlDataAdapter1.UpdateCommand.Parameters.AddW ithValue("@LName", typeof(string)).SourceColumn = "Field2";
this.SqlDataAdapter1.UpdateCommand.Parameters.AddW ithValue("@id", typeof(int)).SourceColumn = "ID";
//Initialize INSERT Command.
this.SqlDataAdapter1.InsertCommand = newSqlCommand("INSERT INTO Register (FName, LName) VALUES (@FName, @LName)", this.SqlConnection1);
this.SqlDataAdapter1.InsertCommand.Parameters.AddW ithValue("@field1", typeof(string)).SourceColumn = "FName";
this.SqlDataAdapter1.InsertCommand.Parameters.AddW ithValue("@field2", typeof(string)).SourceColumn = "LName";
//Initialize DELETE Command.
this.SqlDataAdapter1.DeleteCommand = newSqlCommand("DELETE FROM Register WHERE ID = @id", this.SqlConnection1);
this.SqlDataAdapter1.DeleteCommand.Parameters.AddW ithValue("@id", typeof(int)).SourceColumn = "ID";
this.dataGridView1.Columns["ID"].Visible = false;
this.dataGridView1.Columns["FName"].HeaderText = "ں«ê";
this.dataGridView1.Columns["LName"].HeaderText = "هںêیéی";


}
privatevoid button1_Click(object sender, EventArgs e)
{
this.SqlDataAdapter1.Update(ObjDataSet, "Re");
}
}

hassan razavi
چهارشنبه 21 فروردین 1387, 08:52 صبح
this.SqlDataAdapter1.UpdateCommand = newSqlCommand("UPDATE Register SET Fname = @FName, LName = @LName WHERE ID = @id", this.SqlConnection1);
this.SqlDataAdapter1.UpdateCommand.Parameters.AddW ithValue("@FName", typeof(string)).SourceColumn = "Field1";
this.SqlDataAdapter1.UpdateCommand.Parameters.AddW ithValue("@LName", typeof(string)).SourceColumn = "Field2";
this.SqlDataAdapter1.UpdateCommand.Parameters.AddW ithValue("@id", typeof(int)).SourceColumn = "ID";

در کد بالا بجای Field1 و Field2 بگذارید FName و LName

top7news
جمعه 20 اردیبهشت 1387, 16:16 عصر
یه سئوال
چرا از this اینهمه استفاده شده
لزورمی داشته؟