Mit Chauhan
New member
JAI MATADI all ..
m trying to update my database in asp.net with mssql ..
what m trying to do here is i have to show the Fullname of the User in TEXTBOX2 so that he/she can come to know what he/she already has written in their profile ..
but when m writing something in my TEXTBOX2 and clicking on the BUTTON m not able to update my query .. although m getting the LABEL1.TEXT = "updated" in my web page . .
means it is going there but not able to change my TEXTBOX2's value which i have defined at onload ..
i have to show it in the TEXTBOX2 .. m able to work like this in php very well but facing problem in ASP.NET .. tell me what to do .. here is my code ..
------------------------------------------------
(C#) mytry.aspx
-----------------------
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server" ReadOnly="true"></asp:TextBox>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<br />
<asp:Button ID="Button1" runat="server" Text="change name"
onclick="Button1_Click" />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</div>
</form>
------------------------------------------------
mytry.aspx.cs
------------------
using System.Data.SqlClient;
using System.Data;
using System.IO;
public partial class mytry : System.Web.UI.Page
{
public string connstr = @"Data Source=.\SQLEXPRESS;AttachDbFilename=F:\matromonial1\App_Data\Database.mdf;Integrated Security=True;User Instance=True";
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(connstr);
conn.Open();
string qry;
qry = "select * from signup where username='rahul'";
SqlCommand cmd = new SqlCommand(qry, conn);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds,"table");
conn.Close();
TextBox1.Text = ds.Tables["table"].Rows[0]["username"].ToString();
TextBox2.Text = ds.Tables["table"].Rows[0]["fullname"].ToString();
//GridView1.DataSource = ds.Tables["table"];
// GridView1.DataBind();
}
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(connstr);
conn.Open();
string qry;
qry = "update signup set fullname='" + TextBox2.Text + "' where username='" + TextBox1.Text + "'";
SqlCommand cmd = new SqlCommand(qry, conn);
int i;
i = cmd.ExecuteNonQuery();
if (i > 0)
{
//Response.Write("Updated");
Label1.Text = "updated";
}
else
{
Response.Write("Error");
Label1.Text = "error";
}
}
}
------------------------
m trying to update my database in asp.net with mssql ..
what m trying to do here is i have to show the Fullname of the User in TEXTBOX2 so that he/she can come to know what he/she already has written in their profile ..
but when m writing something in my TEXTBOX2 and clicking on the BUTTON m not able to update my query .. although m getting the LABEL1.TEXT = "updated" in my web page . .
means it is going there but not able to change my TEXTBOX2's value which i have defined at onload ..
i have to show it in the TEXTBOX2 .. m able to work like this in php very well but facing problem in ASP.NET .. tell me what to do .. here is my code ..
------------------------------------------------
(C#) mytry.aspx
-----------------------
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server" ReadOnly="true"></asp:TextBox>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<br />
<asp:Button ID="Button1" runat="server" Text="change name"
onclick="Button1_Click" />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</div>
</form>
------------------------------------------------
mytry.aspx.cs
------------------
using System.Data.SqlClient;
using System.Data;
using System.IO;
public partial class mytry : System.Web.UI.Page
{
public string connstr = @"Data Source=.\SQLEXPRESS;AttachDbFilename=F:\matromonial1\App_Data\Database.mdf;Integrated Security=True;User Instance=True";
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(connstr);
conn.Open();
string qry;
qry = "select * from signup where username='rahul'";
SqlCommand cmd = new SqlCommand(qry, conn);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds,"table");
conn.Close();
TextBox1.Text = ds.Tables["table"].Rows[0]["username"].ToString();
TextBox2.Text = ds.Tables["table"].Rows[0]["fullname"].ToString();
//GridView1.DataSource = ds.Tables["table"];
// GridView1.DataBind();
}
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(connstr);
conn.Open();
string qry;
qry = "update signup set fullname='" + TextBox2.Text + "' where username='" + TextBox1.Text + "'";
SqlCommand cmd = new SqlCommand(qry, conn);
int i;
i = cmd.ExecuteNonQuery();
if (i > 0)
{
//Response.Write("Updated");
Label1.Text = "updated";
}
else
{
Response.Write("Error");
Label1.Text = "error";
}
}
}
------------------------