fufuli
پنج شنبه 15 اسفند 1387, 20:50 عصر
سلام
من دارم برنامه انتخاب واحد می نویسم. به این صورت که چندتا درس تویdatagridview برای کاربر نمایش داده میشه که کنار هر درس یک checkbox هست.کاربر توی textbox شماره دانشجویی خود رو وارد میکنه، دروسی رو که میخوات تیک میزنه و دکمه اعمال رو میزنه. این کد روی باتن هست:
private
void btn_emal_Click(object sender, EventArgs e)
{
Boolean bValue;
int a = grd_dorouseterm.RowCount;
objCommand.Connection = objConnection3;
objConnection3.Open();
for (int i = 0; i < a; i++)
{
bValue = Convert.ToBoolean(grd_dorouseterm.Rows[i].Cells["Column1"].Value);
objCommand.CommandText = "INSERT INTO Entekhab_Vahed(id_stu,id_dars) VALUES(@id_stu,@id_dars)";
objCommand.Parameters.AddWithValue("@id_stu", textBox1.Text);
objCommand.Parameters.AddWithValue("@id_dars", grd_dorouseterm.Rows[i].Cells["id_dars"].Value);
if (bValue == true)
{
objCommand.ExecuteNonQuery();
MessageBox.Show("worked!");
}
}
objConnection3.Close();
}
مشکل اینه که این کد فقط اولین درس انتخاب شده رو به دیتابیس اضافه میکنه و برای دروس بعدی، این رو میده:
The variable name ‘@id_stu’ has already been declared. Variable names must be unique within a query batch or stored procedure.
چی کار کنم؟؟!!
خیلی ممنون
من دارم برنامه انتخاب واحد می نویسم. به این صورت که چندتا درس تویdatagridview برای کاربر نمایش داده میشه که کنار هر درس یک checkbox هست.کاربر توی textbox شماره دانشجویی خود رو وارد میکنه، دروسی رو که میخوات تیک میزنه و دکمه اعمال رو میزنه. این کد روی باتن هست:
private
void btn_emal_Click(object sender, EventArgs e)
{
Boolean bValue;
int a = grd_dorouseterm.RowCount;
objCommand.Connection = objConnection3;
objConnection3.Open();
for (int i = 0; i < a; i++)
{
bValue = Convert.ToBoolean(grd_dorouseterm.Rows[i].Cells["Column1"].Value);
objCommand.CommandText = "INSERT INTO Entekhab_Vahed(id_stu,id_dars) VALUES(@id_stu,@id_dars)";
objCommand.Parameters.AddWithValue("@id_stu", textBox1.Text);
objCommand.Parameters.AddWithValue("@id_dars", grd_dorouseterm.Rows[i].Cells["id_dars"].Value);
if (bValue == true)
{
objCommand.ExecuteNonQuery();
MessageBox.Show("worked!");
}
}
objConnection3.Close();
}
مشکل اینه که این کد فقط اولین درس انتخاب شده رو به دیتابیس اضافه میکنه و برای دروس بعدی، این رو میده:
The variable name ‘@id_stu’ has already been declared. Variable names must be unique within a query batch or stored procedure.
چی کار کنم؟؟!!
خیلی ممنون