update access database

Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Nov 2008
Posts: 27
Reputation: ayi_102 is an unknown quantity at this point 
Solved Threads: 0
ayi_102 ayi_102 is offline Offline
Light Poster

update access database

 
0
  #1
Jan 5th, 2009
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();
}
}
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 2,065
Reputation: Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice 
Solved Threads: 256
Featured Poster
Ramy Mahrous's Avatar
Ramy Mahrous Ramy Mahrous is offline Offline
Postaholic

Re: update access database

 
0
  #2
Jan 5th, 2009
What the problem?
BI Developer | LINKdotNET
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,735
Reputation: LizR has a spectacular aura about LizR has a spectacular aura about 
Solved Threads: 186
LizR LizR is offline Offline
Posting Virtuoso

Re: update access database

 
0
  #3
Jan 6th, 2009
please use code tags so we can read your code.
Did I just hear "You gotta help us, Doc. We've tried nothin' and we're all out of ideas" ? Is this you? Dont let this be you! I will put in as much effort as you seem to.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 27
Reputation: ayi_102 is an unknown quantity at this point 
Solved Threads: 0
ayi_102 ayi_102 is offline Offline
Light Poster

Re: update access database

 
0
  #4
Jan 6th, 2009
coz i am a newbie, so i dont know how to use the code tag.

this is test the code tag
  1.  
  2. private void Search_Click()
  3. {
  4.  
  5. string strSearch = "";
  6.  
  7. //grab the value from html txtsearch (works fine)
  8. strSearch = Request.Form["txtSearch"].ToString();
  9.  
  10. string _ddsearch = "";
  11.  
  12.  
  13. //make strSearch as _ddsearch and grab the value (works fine)
  14. try
  15. { _ddsearch = strSearch; }
  16. catch { }
  17.  
  18. if (strSearch == null || strSearch == "")
  19. {
  20. lblError.Text = "Item ID is missing.";
  21. }
  22.  
  23. else
  24. {
  25. // See if the site can be found
  26. mydb thedb = new mydb();
  27. MyGlobal oapp = new MyGlobal();
  28.  
  29. //define the reader
  30. System.Data.OleDb.OleDbDataReader theReader = null;
  31.  
  32. //defining sql
  33. string _sql = "SELECT * FROM search WHERE ddsearch = " + _ddsearch;
  34. string _sqlupdate = "";
  35.  
  36. //execute the reader
  37. theReader = thedb.SQLExecute_Reader(_sql);
  38.  
  39. if (theReader != null)
  40. {
  41. if (theReader.HasRows == true)
  42. {
  43. while (theReader.Read())
  44. {
  45. int _newnum = 0;
  46.  
  47. // adding count increment 1
  48. string _oldnum = theReader["searchcount"].ToString();
  49. _newnum = Convert.ToInt32(_oldnum) + 1;
  50.  
  51. _sqlupdate = "Update search Set searchcount = " + _newnum.ToString() + " where ddsearch = " + _ddsearch;
  52.  
  53. }
  54. }
  55. else
  56. {
  57. // New Record
  58.  
  59. int _newID = 0;
  60.  
  61. // adding count increment 1
  62. string _oldID = theReader["ID"].ToString();
  63. _newID = Convert.ToInt32(_oldID) + 1;
  64.  
  65. _sqlupdate = "Insert into search (ID,ddsearch,searchcount) values ( " + _newID + " ," + _ddsearch + ", 1)";
  66.  
  67. }
  68.  
  69. thedb.SQLExecute(_sqlupdate);
  70. }
  71. }
  72.  
  73. }


my problem is it cannot read the access database using sql reader

well, basically i am developing a website so i grab the value from html txtSearch with request .... and put it in variables
and the read the access database

if the value in the ddsearch is exist, update just by increment the count
if not exist insert a new row like

ID, ddsearch , searchcount

1 abc 15 if the keyword found, update the search count

if some one enter efg which is not in the ddsearch, insert whole row

ID, ddsearch , searchcount

1 abc 15
2 efg 1 ID become 2 , dd search is efg and search count start from 1

hope this explanation clear enogh
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,735
Reputation: LizR has a spectacular aura about LizR has a spectacular aura about 
Solved Threads: 186
LizR LizR is offline Offline
Posting Virtuoso

Re: update access database

 
0
  #5
Jan 6th, 2009
What error do you get?
Last edited by LizR; Jan 6th, 2009 at 4:40 pm.
Did I just hear "You gotta help us, Doc. We've tried nothin' and we're all out of ideas" ? Is this you? Dont let this be you! I will put in as much effort as you seem to.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 27
Reputation: ayi_102 is an unknown quantity at this point 
Solved Threads: 0
ayi_102 ayi_102 is offline Offline
Light Poster

Re: update access database

 
0
  #6
Jan 6th, 2009
no error actually

when u set break point, it is not getting the reader value

i mean it cannot read the database


theReader = thedb.SQLExecute_Reader(_sql);

if (theReader != null)

after the if, it goes to the end of loop

it is not execute the next line to read the database

i wonder whether my sql query wrong
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,735
Reputation: LizR has a spectacular aura about LizR has a spectacular aura about 
Solved Threads: 186
LizR LizR is offline Offline
Posting Virtuoso

Re: update access database

 
0
  #7
Jan 6th, 2009
I dont see any code for where you open your access database?
Did I just hear "You gotta help us, Doc. We've tried nothin' and we're all out of ideas" ? Is this you? Dont let this be you! I will put in as much effort as you seem to.
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 2,065
Reputation: Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice 
Solved Threads: 256
Featured Poster
Ramy Mahrous's Avatar
Ramy Mahrous Ramy Mahrous is offline Offline
Postaholic

Re: update access database

 
0
  #8
Jan 6th, 2009
Debug!
BI Developer | LINKdotNET
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 27
Reputation: ayi_102 is an unknown quantity at this point 
Solved Threads: 0
ayi_102 ayi_102 is offline Offline
Light Poster

Re: update access database

 
0
  #9
Jan 6th, 2009
mydb thedb = new mydb();
MyGlobal oapp = new MyGlobal();

ups, the code oleDb connection is in the mydb() method
i put it in separate file

well, i found my mistake

there are no error

the error is my access database coz it did not read the search table

when i read the other table, the code can read the rows

i have to recreate the access database again

thank you for the help
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC