ei have single stored procedure in which, i have put poly statements (insert, update and delete) by using if condition [if @mode='insert' (insert into tablename (id,ab,cd,) values(@id,@ab,@cd).
now problem is "i am using connection class from appcode folder of asp.net. in which i have given connection string and build objects of sqlcommand, sql commandtype, datareader, data set, data adapter. now i am having problem in insert data from textbox to sql server. the problem is i do not know, how to concatenate string and values."
in normal we can use cmd.Parameters.AddWithValue("@mode", "Insert"); but now i do not know how would i use @mode='insert' . please help
Aseem BhardwajPosted Sep 9, 2016, 9:26 AM
Midhun TpPosted Sep 9, 2016, 9:14 AM
Midhun TpPosted Sep 9, 2016, 9:09 AM
Aseem BhardwajPosted Sep 9, 2016, 9:06 AM
Aseem BhardwajPosted Sep 9, 2016, 9:01 AM
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string un = Request.QueryString.Get("userName").ToString();
string q = "select * from customerRegistration where userName='" + un + "'";
Connections con = new Connections();
con.ExecuteSelect(q);
con.dr.Read();
userNameText.Text = con.dr["userName"].ToString();
clientNameText.Text = con.dr["nameClient"].ToString();
addressText.Text = con.dr["cAddress"].ToString();
cityText.Text = con.dr["city"].ToString();
stateText.Text = con.dr["state"].ToString();
ctDropDownList.Text = con.dr["clientType"].ToString();
cPersonText.Text = con.dr["contactPerson"].ToString();
emailText.Text = con.dr["email"].ToString();
pNumberText.Text = con.dr["phone"].ToString();
mNumberText.Text = con.dr["mobile"].ToString();
vatText.Text = con.dr["vatNumber"].ToString();
}
}
protected void updateButton_Click(object sender, EventArgs e)
{
string un, cn, add, ct, st, cLt, cp, eMail, phn, mob, vat;
un = Request.QueryString.Get(0).ToString();
cn = clientNameText.Text;
add = addressText.Text;
ct = cityText.Text;
st = stateText.Text;
cLt = ctDropDownList.Text;
cp = cPersonText.Text;
eMail= emailText.Text;
phn = pNumberText.Text;
mob = mNumberText.Text;
vat = vatText.Text;
string q = "update customerRegisteration set nameClient='" + cn + "', cAddress='" + add + "', city='" + ct + "', state='" + st + "', clientType='" + cLt + "', contactPerson='" + cp + "', email='" + eMail + "', phone='" + phn + "', mobile='" + mob + "', vatNumber='" + vat + "' where userName='" + un + "'";
Connections con = new Connections();
con.ExecuteNonSelect(q);
exLabel.Text = "Record Updated Successfully.";
}
}
Aseem BhardwajPosted Sep 9, 2016, 8:55 AM
u = userNameText.Text;
p = passwordText.Text;
string q = "select * from userRegister where userName='" + u + "' and password='" + p + "'";
SqlConnection con = new SqlConnection("Data Source=sam-pc;Initial Catalog=decentComputers;uid=sa;pwd=123");
SqlCommand cmd = new SqlCommand(q, con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
if (dt.Rows.Count > 0)
{
Response.Redirect("userPanel/queryPage.aspx");
}
else
{
ClientScript.RegisterStartupScript(Page.GetType(), "validation", "");
}
Midhun TpPosted Sep 7, 2016, 7:57 AM