V
Viktor Popov
Hi ,
I have a form in which I show UserInfo from the DataBase using Stored
Procedure and I populate 5 TextBox controls with this information in this
way:
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
SqlConnection conn = new SqlConnection("Data Source=BLEK;Initial
Catalog=Estate; User ID=haha; Password=*******");
SqlDataAdapter dad = new SqlDataAdapter("prRTUSERINFO", conn);
dad.SelectCommand.CommandType=CommandType.StoredProcedure;
conn.Open();
dad.SelectCommand.Parameters.Add(new SqlParameter("@USRNAM",
SqlDbType.VarChar,20));
dad.SelectCommand.Parameters["@USRNAM"].Value =
Session["usrName"].ToString();
DataSet ds = new DataSet();
dad.Fill(ds, "Users");
NameTB.Text=ds.Tables["Users"].Rows[0][3].ToString();
PhoneTB.Text=ds.Tables["Users"].Rows[0][5].ToString();
AddressTB.Text=ds.Tables["Users"].Rows[0][6].ToString();
CityTB.Text=ds.Tables["Users"].Rows[0][4].ToString();
EmailTB.Text=ds.Tables["Users"].Rows[0][7].ToString();
usrID=Int32.Parse(ds.Tables["Users"].Rows[0][0].ToString());
conn.Close();
}
The user could see the info and change the Text in the TextBoxes.
On the same form I have an InsertButton and when I click it I would like to
update the information in the DataBase with the changed information. If the
info is not changed and the Button is clicked I update the DataBase with the
same info from The TextBoxes. The problem is that when I have tried to
change the text in the TextBoxes and than I clicked the Button nothing
happens. The same info was in the TexBoxes, I mean the info which was in the
TextBoxes when the page was loaded for the first time.
Here it is the code of the Button_Click:
private void InsertBtn_Click(object sender, System.EventArgs e)
{
SqlConnection conn = new SqlConnection("Data Source=BLEK;Initial
Catalog=Estate; User ID=haha; Password=******");
SqlDataAdapter dada = new SqlDataAdapter();
dada.UpdateCommand = new SqlCommand("UPDATE HAHA.USERS SET
RealName=@NAME,UserCity=@CITY,UserPhone=@PHONE,UserAddr=@ADDR,UserEmail=@EML
WHERE Username=@USRNAME",conn);
dada.UpdateCommand.CommandType = CommandType.Text;
dada.UpdateCommand.Parameters.Add(new SqlParameter("@NAME",
SqlDbType.VarChar,64));
dada.UpdateCommand.Parameters["@NAME"].Value = NameTB.Text.Trim();
dada.UpdateCommand.Parameters.Add(new SqlParameter("@CITY",
SqlDbType.VarChar,20));
dada.UpdateCommand.Parameters["@CITY"].Value = CityTB.Text.Trim();
dada.UpdateCommand.Parameters.Add(new SqlParameter("@PHONE",
SqlDbType.VarChar,16));
dada.UpdateCommand.Parameters["@PHONE"].Value = PhoneTB.Text.Trim();
dada.UpdateCommand.Parameters.Add(new SqlParameter("@ADDR",
SqlDbType.VarChar,74));
dada.UpdateCommand.Parameters["@ADDR"].Value = AddressTB.Text.Trim();
dada.UpdateCommand.Parameters.Add(new SqlParameter("@EML",
SqlDbType.VarChar,64));
dada.UpdateCommand.Parameters["@EML"].Value = EmailTB.Text.Trim();
dada.UpdateCommand.Parameters.Add(new SqlParameter("@USRNAME",
SqlDbType.VarChar,20));
dada.UpdateCommand.Parameters["@USRNAME"].Value =
Session["usrName"].ToString();
conn.Open();
dada.UpdateCommand.ExecuteNonQuery();
conn.Close();
}
Could you tell me where I am wrong?
Thank you in advance!
Viktor
I have a form in which I show UserInfo from the DataBase using Stored
Procedure and I populate 5 TextBox controls with this information in this
way:
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
SqlConnection conn = new SqlConnection("Data Source=BLEK;Initial
Catalog=Estate; User ID=haha; Password=*******");
SqlDataAdapter dad = new SqlDataAdapter("prRTUSERINFO", conn);
dad.SelectCommand.CommandType=CommandType.StoredProcedure;
conn.Open();
dad.SelectCommand.Parameters.Add(new SqlParameter("@USRNAM",
SqlDbType.VarChar,20));
dad.SelectCommand.Parameters["@USRNAM"].Value =
Session["usrName"].ToString();
DataSet ds = new DataSet();
dad.Fill(ds, "Users");
NameTB.Text=ds.Tables["Users"].Rows[0][3].ToString();
PhoneTB.Text=ds.Tables["Users"].Rows[0][5].ToString();
AddressTB.Text=ds.Tables["Users"].Rows[0][6].ToString();
CityTB.Text=ds.Tables["Users"].Rows[0][4].ToString();
EmailTB.Text=ds.Tables["Users"].Rows[0][7].ToString();
usrID=Int32.Parse(ds.Tables["Users"].Rows[0][0].ToString());
conn.Close();
}
The user could see the info and change the Text in the TextBoxes.
On the same form I have an InsertButton and when I click it I would like to
update the information in the DataBase with the changed information. If the
info is not changed and the Button is clicked I update the DataBase with the
same info from The TextBoxes. The problem is that when I have tried to
change the text in the TextBoxes and than I clicked the Button nothing
happens. The same info was in the TexBoxes, I mean the info which was in the
TextBoxes when the page was loaded for the first time.
Here it is the code of the Button_Click:
private void InsertBtn_Click(object sender, System.EventArgs e)
{
SqlConnection conn = new SqlConnection("Data Source=BLEK;Initial
Catalog=Estate; User ID=haha; Password=******");
SqlDataAdapter dada = new SqlDataAdapter();
dada.UpdateCommand = new SqlCommand("UPDATE HAHA.USERS SET
RealName=@NAME,UserCity=@CITY,UserPhone=@PHONE,UserAddr=@ADDR,UserEmail=@EML
WHERE Username=@USRNAME",conn);
dada.UpdateCommand.CommandType = CommandType.Text;
dada.UpdateCommand.Parameters.Add(new SqlParameter("@NAME",
SqlDbType.VarChar,64));
dada.UpdateCommand.Parameters["@NAME"].Value = NameTB.Text.Trim();
dada.UpdateCommand.Parameters.Add(new SqlParameter("@CITY",
SqlDbType.VarChar,20));
dada.UpdateCommand.Parameters["@CITY"].Value = CityTB.Text.Trim();
dada.UpdateCommand.Parameters.Add(new SqlParameter("@PHONE",
SqlDbType.VarChar,16));
dada.UpdateCommand.Parameters["@PHONE"].Value = PhoneTB.Text.Trim();
dada.UpdateCommand.Parameters.Add(new SqlParameter("@ADDR",
SqlDbType.VarChar,74));
dada.UpdateCommand.Parameters["@ADDR"].Value = AddressTB.Text.Trim();
dada.UpdateCommand.Parameters.Add(new SqlParameter("@EML",
SqlDbType.VarChar,64));
dada.UpdateCommand.Parameters["@EML"].Value = EmailTB.Text.Trim();
dada.UpdateCommand.Parameters.Add(new SqlParameter("@USRNAME",
SqlDbType.VarChar,20));
dada.UpdateCommand.Parameters["@USRNAME"].Value =
Session["usrName"].ToString();
conn.Open();
dada.UpdateCommand.ExecuteNonQuery();
conn.Close();
}
Could you tell me where I am wrong?
Thank you in advance!
Viktor