Right i've had a little brake through but got stuck again.
i can get the code below to delete a row if a enter the table name which is stored in the db e.g peopletable
But want be able to delete many different tables rather than one.
tryed to use "dtable" which is a string that gets the name of the table being used and to show the correct datagrid.
But getting an error which am stuck on . any idea's and help would be great thanks for ur time.
Code used to get the table name from a dropdown menu on the poge:
Code:
if (!(DropDownList1.SelectedIndex == 0))
{
myDataGrid.Visible = true;
OleDbDataReader myDataReader;
OleDbCommand myCommand = new OleDbCommand("Select * From ["+DbId+DropDownList1.SelectedItem.Value+"]", objOleDbConn);
try
{
myDataReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
myDataGrid.DataSource = myDataReader;
myDataGrid.DataBind();
// dtable=DbId+DropDownList1.SelectedItem.Value;
TextBox1.Text=DbId+DropDownList1.SelectedItem.Value;
// creating a dataset
OleDbDataAdapter myDataAdapter = new OleDbDataAdapter("SELECT * FROM ["+DbId+DropDownList1.SelectedItem.Value+"]",objOleDbConn);
//DataSet TempDataSet = new DataSet();
myDataAdapter.Fill(TempDataSet, "dbconn");
DataTable TempDataTable = TempDataSet.Tables["["+DbId+DropDownList1.SelectedItem.Value+"]"];
OleDbCommandBuilder TempCmdBuilder = new OleDbCommandBuilder(myDataAdapter);
//foreach (DataRow mydataRow in TempDataSet.Tables["dbconn"].Rows)
}
catch (Exception myException)
{
Response.Write("An error has occurred: " + myException.ToString());
}
}
else
{
myDataGrid.Visible = false;
}
dtable=TextBox1.Text;
the delete code:
Code:
myDataAdapter.SelectCommand = new OleDbCommand("SELECT * FROM ["+dtable+"]",objOleDbConn);
OleDbCommandBuilder custCB = new OleDbCommandBuilder(myDataAdapter);
DataSet custDS = new DataSet();
myDataAdapter.Fill(custDS,"+dtable+");
int rowToDelete = e.Item.ItemIndex;
//custDS.Tables["2uni"].Rows[rowToDelete].Delete();
custDS.Tables["+dtable+"].Rows[rowToDelete].Delete();
myDataAdapter.Update(custDS,"+dtable+");
myDataGrid.DataSource=custDS;
error
Dynamic SQL generation for the DeleteCommand is not supported against a SelectCommand that does not return any key column information.
on
myDataAdapter.Update(custDS,"+dtable+");
thanks for ur time