PDA

View Full Version : سوال: مشکل در ثبت اطلاعات ویرایش شده



helia64
چهارشنبه 11 مرداد 1391, 21:49 عصر
سلام دوستان
بمشکلی دارم با ویرایش کردن اطلاعاتی که ار بانک sql میارم به درون صفحه وب و بعد که تغییر میدم برخی فیلدها رو و دکمه ویرایشم رو میزنم ولی چیزی ثبت نمیشه کدم به صورت زیر هست میشه لطف کنید بگید مشکل من کجاست؟

[CSHA
try

{



SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=NezamPezeshki;Integrated Security=True");

cn.Open();


SqlDataAdapter da = new SqlDataAdapter("select * from Info", cn);


DataTable dt = new DataTable();

da.Fill(dt);


foreach (DataRow r in dt.Rows)

{


SqlDataAdapter d3 = new SqlDataAdapter();


SqlCommand com = new SqlCommand("update DrInfo set Dname=@n,Dfamily=@f,
,Sex=@s (Dname=@n,Dfamily=@f,,Sex=@s)
IdMajor=@idm
" + " where FileRow=" + Label5.Text, cn);

com.Parameters.Add(
"@n", SqlDbType.VarChar).Value = TextBox1.Text;

;

com.Parameters.Add(
"@f", SqlDbType.VarChar).Value = TextBox3.Text;


com.Parameters.Add(
"@idm", SqlDbType.VarChar).Value = Convert.ToInt32(TextBox16.Text);


com.Parameters.Add(
"@s", SqlDbType.VarChar).Value = DropDownList1.Text;


com.ExecuteNonQuery();

}

cn.Close();

Label19.Visible =
true;

Label19.Text =
" ";

}


catch

{

Label19.Visible =
true;

Label19.Text =
" ";

}
RP][/CSHARP]

meisam12
چهارشنبه 11 مرداد 1391, 23:14 عصر
سلام دوست عزیز
من کد شما را به این صورت تغییر دادم و تست کردم درست بود.

SqlConnection con = new SqlConnection(@"Data Source=Meisam-PC\LohSoft;Initial Catalog=CS_ASP_30;user id=sa;password=123");
con.Open();
SqlDataAdapter da = new SqlDataAdapter("select * from Users", con);
DataTable dt = new DataTable();
da.Fill(dt);
foreach (DataRow r in dt.Rows)
{
SqlDataAdapter d3 = new SqlDataAdapter();
SqlCommand com = new SqlCommand("update Users set Username=@n,Password=@f,Email=@s,Age=@idm" + " where UserID=" + txtID.Text, con);
com.Parameters.Add("@n", SqlDbType.VarChar).Value = txtUserName.Text;
com.Parameters.Add("@f", SqlDbType.VarChar).Value = txtPassword.Text;
com.Parameters.Add("@idm", SqlDbType.VarChar).Value = Convert.ToInt32(txtAge.Text);
com.Parameters.Add("@s", SqlDbType.VarChar).Value = txtEmail.Text;
com.ExecuteNonQuery();
}
con.Close();