Code:
private void button1_Click(object sender, System.EventArgs e)
{
try
{
sqlConnection1.Open();
SqlCommand cCommand = sqlConnection1.CreateCommand();
cCommand.CommandText = textBox1.Text;
SqlDataAdapter cAdapter = new SqlDataAdapter();
cAdapter.SelectCommand = cCommand;
DataSet cSet = new DataSet();
cAdapter.Fill(cSet);
//dataGrid1.SetDataBinding(cSet, „“);
dataGrid1.DataSource = cSet.Tables[0];
}
catch (System.Data.SqlClient.SqlException err)
{
MessageBox.Show(err.Message);
return;
}
catch
{
MessageBox.Show(„Ein Fehler ist aufgetreten.“);
return;
}
finally
{
sqlConnection1.Close();
}
}
private void button2_Click(object sender, System.EventArgs e)
{
try
{
sqlConnection1.Open();
SqlCommand cCommand = sqlConnection1.CreateCommand();
cCommand.CommandText = textBox1.Text;
SqlDataAdapter cAdapter = new SqlDataAdapter();
cAdapter.SelectCommand = cCommand;
DataSet cSet = new DataSet();
dataGrid1.DataSource = cSet.Tables[0];
cAdapter.Update(cSet);
}
catch (System.Data.SqlClient.SqlException err)
{
MessageBox.Show(err.Message);
return;
}
catch
{
MessageBox.Show(„Die Tabelle konnte nicht geupdated werden!“);
return;
}
finally
{
sqlConnection1.Close();
}