i am doing the application using grid view.in the database for check box i am using bit datatype.
for the check box in the database field as follows;
Columnname datatype length allownulls
Activate bit 1 1
in the source for the grid view code as follows;
VB.NET
"chkStatus" runat="server"
AutoPostBack="true" OnCheckedChanged="chkStatus_OnCheckedChanged"
Checked=''
Text='' />
itemtemplate>Code
In the aspx page for check box code as follows;Java
public void chkStatus_OnCheckedChanged(object sender, EventArgs e)
{
CheckBox chkStatus = (CheckBox)sender;
GridViewRow row = (GridViewRow)chkStatus.NamingContainer;
string vid = row.Cells[1].Text;
bool status = chkStatus.Checked;
string query = "UPDATE Vendors SET Activate = @Activate WHERE VendorId = @VendorId";
SqlConnection conn = new SqlConnection("Server=(local);initial catalog=master;Trusted_Connection=True");
SqlCommand com = new SqlCommand(query, conn);
com.Parameters.Add("@Activate", SqlDbType.Bit).Value = status;
com.Parameters.Add("@VendorId", SqlDbType.Bit).Value = vid;
conn.Open();
com.ExecuteNonQuery();
conn.Close();
}VB.NET
when i run the grid view it shows the error as follows Object cannot be cast from DBNull to other types. from my coding in the aspx and source page what is error please help me.
Pradip PandeyRank #452 · 5.6K reputationPosted Dec 12, 2012, 12:35 AM EST