Hi i am pretty new to C# and trying to make a delete feature on my website using sql and C# i was wondering if any one could take a look at my code and tell me where im going wrong. Also if you could explain in lamest terms that would be good lol
thanks
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
public partial class Form4 : System.Web.UI.Page
{
protected string id2;
protected string myConnectionString2;
protected void Page_Load(object sender, EventArgs e)
id2 = "0";
myConnectionString2 = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +
this.Server.MapPath("") + "\\hospital.mdb";
}
protected void Button1_Click(object sender, EventArgs e)
int sa;
OleDbConnection myConnection = new OleDbConnection(myConnectionString2);
try
if (TextBox1.Text !=null )
id2 = TextBox1.Text;
OleDbCommand myCommand = new OleDbCommand("DELETE* FROM tblAppointments WHERE appointmentID ='"+id2+"'", myConnection);
OleDbDataAdapter myDataAdapter = new OleDbDataAdapter(myCommand);
myConnection.Open();
sa = myCommand.ExecuteNonQuery();
myConnection.Close();
Label1.Text = "Recored Deleted.";
catch (Exception ex)
Label1.Text = "Database Error!" + ex.Message;