نمایش نتایج 1 تا 3 از 3

نام تاپیک: تو DataGrideبه روز و درج نمیکنه

  1. #1

    Question تو DataGrideبه روز و درج نمیکنه

    سلام.
    این کد مشگلش چیه ؟
    فقط حذف رو تو بانک ذخیره میکنه.
    واسه بقیش خطا می ده
    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.AddWithV alue("@FName", typeof(string)).SourceColumn = "Field1";
    this.SqlDataAdapter1.UpdateCommand.Parameters.AddWithV alue("@LName", typeof(string)).SourceColumn = "Field2";
    this.SqlDataAdapter1.UpdateCommand.Parameters.AddWithV alue("@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.AddWithV alue("@field1", typeof(string)).SourceColumn = "FName";
    this.SqlDataAdapter1.InsertCommand.Parameters.AddWithV alue("@field2", typeof(string)).SourceColumn = "LName";
    //Initialize DELETE Command.
    this.SqlDataAdapter1.DeleteCommand = newSqlCommand("DELETE FROM Register WHERE ID = @id", this.SqlConnection1);
    this.SqlDataAdapter1.DeleteCommand.Parameters.AddWithV alue("@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");
    }
    }

  2. #2

    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

  3. #3
    یه سئوال
    چرا از this اینهمه استفاده شده
    لزورمی داشته؟

قوانین ایجاد تاپیک در تالار

  • شما نمی توانید تاپیک جدید ایجاد کنید
  • شما نمی توانید به تاپیک ها پاسخ دهید
  • شما نمی توانید ضمیمه ارسال کنید
  • شما نمی توانید پاسخ هایتان را ویرایش کنید
  •