Hi
I have to select count(Date) from Appointment table having count<5. If count(Date)<5 then I should insert the data from my page. For that I have given the coding as
[code=c#]
protected void Button3_Click(o bject sender, EventArgs e)
{
SqlConnection con = new SqlConnection(" user id=sa;password= cast;database=H ello_Dr;server= AURORA-SERVER;");
con.Open();
SqlDataReader rd;
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = "select count(Date) from Appointment where Date='" + DateTextBox.Tex t + "'";
//and count(Date)>=5" ;
Int16 cnt;
cnt = cmd.ExecuteScal ar();
if (cnt >= 5)
{
Response.Write( "Plz select another appointment date");
}
else
{
String sql = "insert into Appointment values('" + TextBox1.Text + "','" + TextBox2.Text + "','" + TextBox3.Text + "','" + DateTextBox.Tex t + "','" + TextBox5.Text + "','" + TextBox6.Text + "','" + TextBox7.Text + "','" + TextBox8.Text + "')";
SqlCommand cmd1 = new SqlCommand(sql, con);
cmd1.ExecuteNon Query();
}
}
[/code]
But when I run, I am getting the following error.
Error 1 Cannot implicitly convert type 'object' to 'short'. An explicit conversion exists (are you missing a cast?) E:\suganya\Suga nya_Hello_Dr\Ap pointment.aspx. cs 93 15 E:\suganya\Suga nya_Hello_Dr\
I have to select count(Date) from Appointment table having count<5. If count(Date)<5 then I should insert the data from my page. For that I have given the coding as
[code=c#]
protected void Button3_Click(o bject sender, EventArgs e)
{
SqlConnection con = new SqlConnection(" user id=sa;password= cast;database=H ello_Dr;server= AURORA-SERVER;");
con.Open();
SqlDataReader rd;
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = "select count(Date) from Appointment where Date='" + DateTextBox.Tex t + "'";
//and count(Date)>=5" ;
Int16 cnt;
cnt = cmd.ExecuteScal ar();
if (cnt >= 5)
{
Response.Write( "Plz select another appointment date");
}
else
{
String sql = "insert into Appointment values('" + TextBox1.Text + "','" + TextBox2.Text + "','" + TextBox3.Text + "','" + DateTextBox.Tex t + "','" + TextBox5.Text + "','" + TextBox6.Text + "','" + TextBox7.Text + "','" + TextBox8.Text + "')";
SqlCommand cmd1 = new SqlCommand(sql, con);
cmd1.ExecuteNon Query();
}
}
[/code]
But when I run, I am getting the following error.
Error 1 Cannot implicitly convert type 'object' to 'short'. An explicit conversion exists (are you missing a cast?) E:\suganya\Suga nya_Hello_Dr\Ap pointment.aspx. cs 93 15 E:\suganya\Suga nya_Hello_Dr\
Comment