Alsalamo Alaikom,
first,i want to thank everybody help me before or just think to help me,and also Sorry for intrupting you many times, but now i have a new problem.
Look! I have a table that contain an arabic row and english row, i want to call the the records in Company_Name which is english and put it in a dropdown list or listbox. i tried to make for loop and think in it many times but couldn't reach to a solution.
when i postponed this problem to get a solution i bind the dropdownlist ot listbox with the table so it contains english and arabic records now. my aim is to delete the selected row according to the selected value.
this is the code:
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
sqlDataAdapter1.Fill(dataSet11);
sqlDataAdapter1.Fill(dataSet11);
ListBox1.DataBind();
}
private void Button1_Click(object sender, System.EventArgs e)
{
if(ListBox1.SelectedValue == null)
{
Label2.Text="No items is selected";
}
else
{
SqlCommand cmd1 = new SqlCommand();
cmd1.Connection= sqlConnection1;
cmd1.CommandText="select Company_ID from "
+"Companies where Company_Name='"
+ListBox1.SelectedItem.Text+"'";
sqlConnection1.Open();
int compID =int.Parse(cmd1.ExecuteScalar().ToString());
sqlConnection1.Close();
SqlCommand cmd2= new SqlCommand();
cmd2.Connection= sqlConnection1;
cmd2.CommandText="delete from Companies where "
+"Company_ID="+compID+" or Company_ID="+(compID+1);
sqlConnection1.Open();
cmd2.ExecuteNonQuery();
Label2.Text="You have deleted <b>"+ListBox1.SelectedItem.Text
+" Company <b> successfully;)";
sqlConnection1.Close();
}
}when i build it,no rows was deleted and an error message appears which tells me:
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Line 304: SqlCommand cmd1 = new SqlCommand(); Line 305: cmd1.Connection= sqlConnection1; Line 306: cmd1.CommandText="select Company_ID from " Line 307: +"Companies where Company_Name='" Line 308: +ListBox1.SelectedItem.Text+"'";