Hi, basically i want to delete the whole database! Because when i import an excel file it automatically uploads it to the database. If i were to upload another excel file it will add it to the original one and i don't want that! so... how do i delete the original data!?! :)
code:
private void button2_Click(object sender, EventArgs e)
{
const string con = "Data Source = dqq5ndqef2.database.windows.net; Initial Catalog = Login; Integrated Security = False; User ID = richardjacobs97; Password = ; Connect Timeout = 15; Encrypt = False; TrustServerCertificate = False; ApplicationIntent = ReadWrite; MultiSubnetFailover = False";
using (SqlConnection connection = new SqlConnection(con))
{
connection.Open();
using (SqlTransaction transaction = connection.BeginTransaction())
using (SqlCommand cmd = new SqlCommand("INSERT INTO StaffRota (Id, Name, Date) Values (@Id, @Name, @Date)", connection, transaction))
{
cmd.CommandType = CommandType.Text;
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
cmd.Parameters.Clear();
cmd.Parameters.AddWithValue("@Id", dataGridView1.Rows[i].Cells["Id"].Value);
cmd.Parameters.AddWithValue("@Name", dataGridView1.Rows[i].Cells["Name"].Value);
cmd.Parameters.AddWithValue("@Date", dataGridView1.Rows[i].Cells["Date"].Value);
cmd.ExecuteNonQuery();
}
transaction.Commit();
}
using (SqlCommand cmd = new SqlCommand("SELECT Id, Name, Date FROM StaffRota", connection))
{
DataTable dt = new DataTable();
SqlDataAdapter sda = new SqlDataAdapter(cmd);
sda.Fill(dt);
dataGridView1.DataSource = dt;
}
}
}
would the delete code be like this?
private void button3_Click(object sender, EventArgs e)
{
const string con = "Data Source = dqq5ndqef2.database.windows.net; Initial Catalog = Login; Integrated Security = False; User ID = richardjacobs97; Password = ; Connect Timeout = 15; Encrypt = False; TrustServerCertificate = False; ApplicationIntent = ReadWrite; MultiSubnetFailover = False";
using (SqlConnection connection = new SqlConnection(con))
{
connection.Open();
using (SqlCommand cmd = new SqlCommand("Select Id, Name, Date From StaffRota Values (@Id, @Name, @Date)", connection))
{
}
}
}
}
can anyone help? :)