PDA

View Full Version : دستور آپدیتم در کد زیر کار نمی کنه



alinikooei
شنبه 01 بهمن 1390, 12:15 عصر
سلام دوستان .من یک صفحه درست کردم که باید اطلاعات را تکمیل کنند.نمی دونم چرا دستور آپدیتم کار نمی کنی. آخه هیچ errori هم نمیده.
اینم کدم
publicpartialclassporopozal : System.Web.UI.Page
{
SqlDataAdapter DA = newSqlDataAdapter();
SqlCommand CM = newSqlCommand();
SqlConnection CN = newSqlConnection();
DataSet DS = newDataSet();
string connectionString = @"Server =.; Database = mydb; Trusted_Connection = True ";
protectedvoid Page_Load(object sender, EventArgs e)
{
CN.ConnectionString = connectionString;
CM.Connection = CN;
CM.CommandType = CommandType.Text;
DA.SelectCommand = CM;
CM.CommandText = "select * from poropozal where stud_id=" + Session ["user_id"];
DA.Fill(DS, "poropozal");
DataTable DT = DS.Tables["poropozal"];
if (DT.Rows.Count == 0)
{

return;
}
txtUsername.Text = DT.Rows[0]["stud_id"].ToString();
txtNameFamily.Text = DT.Rows[0]["namevafamily"].ToString();
txtAvrage.Text = DS.Tables["poropozal"].Rows[0]["avarge"].ToString();
txtProf.Text = DS.Tables["poropozal"].Rows[0]["profname"].ToString();
if (DT.Rows[0]["type"].ToString() == "1") rd1.Checked = true;
else rd2.Checked = true;
txtTitle.Text = DS.Tables["poropozal"].Rows[0]["onvankamel"].ToString();
txtMaraje.Text = DS.Tables["poropozal"].Rows[0]["maraje"].ToString();
txtDescript.Text = DS.Tables["poropozal"].Rows[0]["sharheporoje"].ToString();
}

protectedvoid Button1_Click(object sender, EventArgs e)
{
int t;
if (rd1.Checked == true)
t = 1;
else t = 0;
CN.Open();
CM.Connection = CN;
CM.CommandText = "update poropozal set stud_id='" + txtUsername.Text + "' ,namevafamily=N'" + txtNameFamily.Text + "', avarge=" + txtAvrage.Text + ", profname=N'" + txtProf.Text + "', type=" + t + " , onvankamel=N'" + txtTitle.Text + "' , maraje=N'" + txtMaraje.Text + "', sharheporoje=N'" + txtDescript.Text + "' where stud_id="+Session["user_id"];
CM.ExecuteNonQuery();
CN.Close();
}

hjran abdpor
شنبه 01 بهمن 1390, 16:02 عصر
سلام.
کدهاتون را بین تگ ها قرار دهید.

alinikooei
شنبه 01 بهمن 1390, 23:16 عصر
دستور آپدیتم در کد زیر کار نمی کنه

سلام دوستان .من یک صفحه درست کردم که باید اطلاعات را تکمیل کنند.نمی دونم چرا دستور آپدیتم کار نمی کنی. آخه هیچ errori هم نمیده.
اینم کدم


publicpartialclassporopozal : System.Web.UI.Page
{
SqlDataAdapter DA = newSqlDataAdapter();
SqlCommand CM = newSqlCommand();
SqlConnection CN = newSqlConnection();
DataSet DS = newDataSet();
string connectionString = @"Server =.; Database = mydb; Trusted_Connection = True ";
protectedvoid Page_Load(object sender, EventArgs e)
{
CN.ConnectionString = connectionString;
CM.Connection = CN;
CM.CommandType = CommandType.Text;
DA.SelectCommand = CM;
CM.CommandText = "select * from poropozal where stud_id=" + Session ["user_id"];
DA.Fill(DS, "poropozal");
DataTable DT = DS.Tables["poropozal"];
if (DT.Rows.Count == 0)
{

return;
}
txtUsername.Text = DT.Rows[0]["stud_id"].ToString();
txtNameFamily.Text = DT.Rows[0]["namevafamily"].ToString();
txtAvrage.Text = DS.Tables["poropozal"].Rows[0]["avarge"].ToString();
txtProf.Text = DS.Tables["poropozal"].Rows[0]["profname"].ToString();
if (DT.Rows[0]["type"].ToString() == "1") rd1.Checked = true;
else rd2.Checked = true;
txtTitle.Text = DS.Tables["poropozal"].Rows[0]["onvankamel"].ToString();
txtMaraje.Text = DS.Tables["poropozal"].Rows[0]["maraje"].ToString();
txtDescript.Text = DS.Tables["poropozal"].Rows[0]["sharheporoje"].ToString();
}

protectedvoid Button1_Click(object sender, EventArgs e)
{
int t;
if (rd1.Checked == true)
t = 1;
else t = 0;
CN.Open();
CM.Connection = CN;
CM.CommandText = "update poropozal set stud_id='" + txtUsername.Text + "' ,namevafamily=N'" + txtNameFamily.Text + "', avarge=" + txtAvrage.Text + ", profname=N'" + txtProf.Text + "', type=" + t + " , onvankamel=N'" + txtTitle.Text + "' , maraje=N'" + txtMaraje.Text + "', sharheporoje=N'" + txtDescript.Text + "' where stud_id="+Session["user_id"];
CM.ExecuteNonQuery();
CN.Close();
}

کسی جواب گو این سوال من نیست؟