I have a problem about updating access database.
there are 3 columns in my database : ID, searchkeyword, count
in the form there are button n textbox
if user enter a new search keyword, the database updated all
if the keyword already exist, just update count column +1
this is what i got so far
private void Insert()
{
if (TextBox1.Text == null || TextBox1.Text == "")
{
lblError.Text = "Item ID is missing.";
}
string _ddsearch = "";
try
{ _ddsearch = Return_search; }
catch { }
if (_ddsearch == null || _ddsearch == "")
{
lblError.Text = "Item ID is missing.";
}
else
{
// See if the site can be found
mydb thedb = new mydb();
MyGlobal oapp = new MyGlobal();
System.Data.OleDb.OleDbDataReader theReader = null;
string _sql = "SELECT * FROM search WHERE ddsearch = " + _ddsearch;
string _sqlupdate = "";
theReader = thedb.SQLExecute_Reader(_sql);
if (theReader != null)
{
if (theReader.HasRows == false )
{
while (theReader.Read())
{
int _newnum = 0;
string _oldnum = theReader["searchcount"].ToString();
_newnum = Convert.ToInt32(_oldnum) + 1;
_sqlupdate = "Update tracking Set searchcount = " + _newnum.ToString() + " where ddsearch = " + _ddsearch;
}
}
else
{
// New Record
_sqlupdate = "Insert into search (id,searchcount) values (" + _ddsearch + ", 1)";
}
thedb.SQLExecute(_sqlupdate);
}
}
}
private string Return_search
{
get
{
return Request.QueryString["ddsearch"].ToString();
}
}