Collector
چهارشنبه 30 شهریور 1390, 02:18 صبح
من دریک فرم که دو تا دیتا گرید دارد با این کد در یک کلاس اطلاعات را اضافه میکنم .
حالا در دیتا گرید اول اطلاعات را وارد میکنم و بعد در دیتاگرید دوم . دیتاگرید اولی با دومی یکی میشود.
آیا باید از دیتاست جدا استفاده کنم؟ لطفا راهنمایی کنید.
public static void Save(string txt,string Table,string Field)
{
string p;
Int32 i;
SqlDataAdapter da = new SqlDataAdapter("", con);
if (txt != "")
{
ds2.Clear();
da.SelectCommand.CommandText = "select code from " + Table + "";
da.Fill(ds2, "n");
i = End_Record(Table);
p = "insert into " + Table + "(" + Field + ",code) values ('" + txt + "'," + i + " )";
SqlCommand cmd = new SqlCommand(p, con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
da.SelectCommand.CommandText = "select * from " + Table + " order by code";
da.Fill(ds2, "B");
MessageBox.Show("." + "اطلاعات با موفقیت ثبت شد", "اطلاع", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign);
}
else
{
MessageBox.Show("." + "لطفا نوع سقف مورد نظر را وارد کنید", "اطلاع", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign);
}
}
فراخوانی تابع
Class1.Save(txt2.Text, "A", "name_A");
dgv1.DataSource = Class1.ds2;
dgv1.DataMember = "B";
حالا در دیتا گرید اول اطلاعات را وارد میکنم و بعد در دیتاگرید دوم . دیتاگرید اولی با دومی یکی میشود.
آیا باید از دیتاست جدا استفاده کنم؟ لطفا راهنمایی کنید.
public static void Save(string txt,string Table,string Field)
{
string p;
Int32 i;
SqlDataAdapter da = new SqlDataAdapter("", con);
if (txt != "")
{
ds2.Clear();
da.SelectCommand.CommandText = "select code from " + Table + "";
da.Fill(ds2, "n");
i = End_Record(Table);
p = "insert into " + Table + "(" + Field + ",code) values ('" + txt + "'," + i + " )";
SqlCommand cmd = new SqlCommand(p, con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
da.SelectCommand.CommandText = "select * from " + Table + " order by code";
da.Fill(ds2, "B");
MessageBox.Show("." + "اطلاعات با موفقیت ثبت شد", "اطلاع", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign);
}
else
{
MessageBox.Show("." + "لطفا نوع سقف مورد نظر را وارد کنید", "اطلاع", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign);
}
}
فراخوانی تابع
Class1.Save(txt2.Text, "A", "name_A");
dgv1.DataSource = Class1.ds2;
dgv1.DataMember = "B";