Click here to Skip to main content
15,892,537 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
otected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=demo1;Integrated Security=True");
con.Open();

Hide Expand Copy Code
int a = Convert.ToInt32(TextBox1.Text);
int b = Convert.ToInt32(TextBox2.Text);

if (DropDownList1.Text == "add")
{
int sum = (a + b);
Label1.Text = Convert.ToString(sum);
dat.Text = DateTime.Now.ToString();

}
if

(DropDownList1.Text == "sub")
{
int sub = (a - b);
Label1.Text = Convert.ToString(sub);
dat.Text = DateTime.Now.ToString();
}
if
(DropDownList1.Text == "mul")
{
int mul = a * b;
Label1.Text = Convert.ToString(mul);
dat.Text = DateTime.Now.ToString();
}
if
(DropDownList1.Text == "div")
{
decimal div = a / b;
Label1.Text = Convert.ToString(div);
dat.Text = DateTime.Now.ToString();
}

SqlCommand cmd = new SqlCommand();

cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "p";

cmd.Parameters.AddWithValue("@firsttno", TextBox1.Text);
cmd.Parameters.AddWithValue("@secondno", TextBox2.Text);
cmd.Parameters.AddWithValue("@operation", DropDownList1.Text);
cmd.Parameters.AddWithValue("@result", Label1.Text);
cmd.Parameters.AddWithValue("@optime", dat.Text);
cmd.Connection = con;
cmd.ExecuteNonQuery();

con.Close();

}
}
}
Posted
Updated 26-May-15 20:01pm
v2
Comments
Sergey Alexandrovich Kryukov 27-May-15 1:59am    
Aha, the post starting from "otected" :-)
And this is not the main problem. The problem is that this is a code dump, not even formatted. Not a question.
—SA
willington.d 27-May-15 2:00am    
Are you getting any error???

Bro this is because you are not getting any value to save.
The if Condition you gave is wrong..
It should be
if (DropDownList1.SelectedValue== "add")
{
}
 
Share this answer
 
Comments
Member 11507028 27-May-15 2:33am    
the result showing in lebel but it is not storing in databasee
Manoj Sawant 27-May-15 4:31am    
can you show me what procedure you have written
create procedure p
(
@firsttno int,
@secondno int,
@operation varchar(max),
@result int,
@optime datetime
)
as begin
select firstno,secondno,operation,result,optime from table1 where firstno=@firsttno and secondno=@secondno and operation=@operation and result=@result and optime=@optime
end
 
Share this answer
 
Comments
Manoj Sawant 27-May-15 6:17am    
Bro you have select query in the procedure whereas you must have a insert query instead of select query
create procedure p
(
@firsttno int,
@secondno int,
@operation varchar(max),
@result int,
@optime datetime
)
as begin
Insert into table1(firstno,secondno,operation,result,optime) Values(@firsttno,@secondno,@operation,@result,@optime)
end

In C# code

SqlCommand cmd = new SqlCommand();

cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "p";

cmd.Parameters.AddWithValue("@firsttno", TextBox1.Text);
cmd.Parameters.AddWithValue("@secondno", TextBox2.Text);
cmd.Parameters.AddWithValue("@operation", DropDownList1.SelectedValue);
cmd.Parameters.AddWithValue("@result", Label1.Text);
cmd.Parameters.AddWithValue("@optime", dat.Text);
cmd.Connection = con;
cmd.ExecuteNonQuery();
 
Share this answer
 
Comments
Member 11507028 27-May-15 6:29am    
thank u i did some mistakes here and in coding section i have not converted the value to date time...
thank you everybody

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900