Reputation: 47
protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
{
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select FromYear from Factory where Cal_ID='" + DropDownList1.SelectedItem.Text + "'";
cmd.Connection = con;
con.Open();
dr = cmd.ExecuteReader();
dr.Read();
d = dr[0].ToString();
//d =(string) Label4.Text;
con.Close();
}
I want integer value from database
Upvotes: 0
Views: 25179
Reputation: 13381
try
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select FromYear from Factory where Cal_ID='" + DropDownList1.SelectedItem.Text + "'";
cmd.Connection = con;
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
dr.Read();
int d = dr.GetInt32(0);
con.Close();
dr.GetInt32(0)
should read an int at position 0
Upvotes: 3
Reputation: 21
string InvAmountQuery = "SELECT InvAmount FROM Registration WHERE Email='" + useremail + "' ";
SqlCommand InvAmountcom = new SqlCommand(InvAmountQuery, conn);
int InvAmount = Convert.ToInt32(InvAmountcom.ExecuteScalar().ToString());
Upvotes: 0
Reputation: 1058
protected void Calendar1_DayRender(object sender, DayRenderEventArgs e) { SqlCommand cmd = new SqlCommand(); cmd.CommandType = CommandType.Text; cmd.CommandText = "select FromYear from Factory where Cal_ID='" + DropDownList1.SelectedItem.Text + "'"; cmd.Connection = con; con.Open(); d = GetYear(cmd).ToString(); con.Close(); }
the "dirty" work is done by GetYear :
private const DEFAULT_YEAR = 2000; private int GetYear(System.Data.IDbCommand command) { int year = DEFAULT_YEAR; using (System.Data.IDataReader reader = command.ExecuteReader()) { if (reader.Read()) { year = GetIntOrDefault(reader, 0); } } return year; } private int GetIntOrDefault(System.Data.IDataRecord record, int ordinal) { if (record.IsDBNull(ordinal)) { return DEFAULT_YEAR; } else { return record.GetInt32(ordinal); } }
Upvotes: 1