Some Error Please help

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Mar 2008
Posts: 268
Reputation: Traicey is an unknown quantity at this point 
Solved Threads: 19
Traicey's Avatar
Traicey Traicey is offline Offline
Posting Whiz in Training

Some Error Please help

 
0
  #1
Jun 20th, 2009
Hi all

I am trying to retrieve a data from Oracle database and display it in the textboxes to be editable but with no luck, am getting a ORA error, missing right parenthesis, that sounds easy and I also thought, I put in the right parenthisis but still it is complaining with it and my guess is that it looking for theInsert keyword since I have the into keyword but instead it is finding select

Please see the below code and tell me what could be wrong or alternative way to do this

  1. string lid = "";
  2. string bid = "";
  3. string mid = "";
  4. string ldate = "";
  5. string rdate = "";
  6. string famount = "";
  7. string fpaid = "";
  8.  
  9. string stringConn = "Data source=127.0.0.1; user id=*********; Password=*************;";
  10. OracleConnection conn = new OracleConnection(stringConn);
  11. conn.Open();
  12. string sql = "Select LoanID, BookID, MemberID, LoanDate, ReturnDate, FineAmount, FinePaid";
  13. sql += " INTO('" + lid + "', '" + bid + "', '" + mid + "', '" + ldate + "', '" + rdate + "', '" + famount + "', '" + fpaid + "')";
  14. sql += "From Loan Where loanID = " + "'" + lid + "'";
  15.  
  16. txtLoanID.Text = lid;
  17. txtBookID.Text = bid;
  18. txtMemberID.Text = mid;
  19. txtLoanDate.Text = ldate;
  20. txtReturnDate.Text = rdate;
  21. txtFineAmount.Text = famount;
  22. txtFinePaid.Text = fpaid;
  23. OracleCommand cmd = new OracleCommand(sql, conn);
  24. int ok = cmd.ExecuteNonQuery();
Some people get so rich they lose all respect for humanity. That's how rich I want to be.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 3,204
Reputation: sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of 
Solved Threads: 571
Sponsor
sknake's Avatar
sknake sknake is online now Online
.NET Enthusiast

Re: Some Error Please help

 
0
  #2
Jun 20th, 2009
Your syntax should be:
  1. INSERT INTO Table (Col1, Col2, Col3)
  2. SELECT Col1, Col2, Col3
  3. FROM SomeOtherTable
Scott Knake
Custom Software Development
Apex Software, Inc.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 268
Reputation: Traicey is an unknown quantity at this point 
Solved Threads: 19
Traicey's Avatar
Traicey Traicey is offline Offline
Posting Whiz in Training

Re: Some Error Please help

 
0
  #3
Jun 20th, 2009
I dont think I understand what ur trying to say can u elaborarte a bit,

Thanks
Some people get so rich they lose all respect for humanity. That's how rich I want to be.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 3,204
Reputation: sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of 
Solved Threads: 571
Sponsor
sknake's Avatar
sknake sknake is online now Online
.NET Enthusiast

Re: Some Error Please help

 
0
  #4
Jun 20th, 2009
Actually, you have a lot of problems here. You're declaring your variables as string.Empty and then you're assembling a string with them:
  1. sql += " INTO('" + lid + "', '" + bid + "', '" ....
Evaluates to:
  1. INTO('','','' ....
Notice how the column names would be missing, and what you should be doing is first using parameterized SQL, see threads:
http://www.daniweb.com/forums/thread191241.html
http://www.daniweb.com/forums/thread198304.html

Next your query should look like (if you continue dynamically building queries like this)
  1. INSERT INTO TableToInsert (lid, bid, MID, ldate, rdate, famount, fpaid)
  2. SELECT LoanID, BookID, MemberID, LoanDate, ReturnDate, FineAmount, FinePaid
  3. FROM Loan
  4. WHERE loadId = 12345

And the value of the fields you initialized is never changed after they are initialized, so I do not understand why you are setting a text box with those values:

These are never set after initialization in the code you posted:
  1. string lid = "";
  2. string bid = "";
  3. string mid = "";
  4. string ldate = "";
  5. string rdate = "";
  6. string famount = "";
  7. string fpaid = "";
Scott Knake
Custom Software Development
Apex Software, Inc.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 268
Reputation: Traicey is an unknown quantity at this point 
Solved Threads: 19
Traicey's Avatar
Traicey Traicey is offline Offline
Posting Whiz in Training

Re: Some Error Please help

 
0
  #5
Jun 20th, 2009
Here it goes,

I want to get(Select) values from the Database and bind them into Textboxes, then the user can edit them and update them that means writting them to the database again with the new values from textbox, in this moment in time I dont wana insert anything to my database, I wana get it from the database bind it to textboxes, if U know what I mean but Im getting an error "MISSING WRITE PARANTHESIS" and I know its not the case, I just wana find out why is complaining with such error

Maybe I dont understand where u getting at, so can u do me a favor instead of breaking the code, maybe just write all of it the way u think it should be
Last edited by Traicey; Jun 20th, 2009 at 10:50 am.
Some people get so rich they lose all respect for humanity. That's how rich I want to be.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 3,204
Reputation: sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of 
Solved Threads: 571
Sponsor
sknake's Avatar
sknake sknake is online now Online
.NET Enthusiast

Re: Some Error Please help

 
0
  #6
Jun 20th, 2009
Your query is badly formed so that is probably just a best-guess error that Oracle is spitting out. Ignore it for now. Why are you writing an Into() query if you're trying to select values? What you should be doing is reading a datatable to get the values in to text boxes. Use this example but move it over to oracle:
  1. private void button1_Click(object sender, EventArgs e)
  2. {
  3. const string connStr = "Data Source=apex2006sql;Initial Catalog=Leather;Integrated Security=True;";
  4. const string query = "Select * From Invoice Where InvNumber = @InvNumber";
  5. using (DataTable dt = new DataTable())
  6. {
  7. using (SqlConnection conn = new SqlConnection(connStr))
  8. {
  9. conn.Open();
  10. using (SqlCommand cmd = new SqlCommand(query, conn))
  11. {
  12. cmd.Parameters.Add(new SqlParameter("@InvNumber", 1100));
  13. using (SqlDataReader dr = cmd.ExecuteReader())
  14. {
  15. dt.Load(dr);
  16. }
  17. }
  18. conn.Close();
  19. }
  20. if (dt.Rows.Count != 1)
  21. throw new Exception("Record not found!");
  22. DataRow row = dt.Rows[0];
  23.  
  24. int invNumber = Convert.ToInt32(row["InvNumber"]);
  25. string invStatis = Convert.ToString(row["InvStatus"]);
  26. //Bind the text boxes after you have the values
  27. System.Diagnostics.Debugger.Break();
  28. }
  29. }

You could also use a DataSet if you wanted to do property binding with the text boxes.
Last edited by sknake; Jun 20th, 2009 at 11:07 am. Reason: missed a dispose
Scott Knake
Custom Software Development
Apex Software, Inc.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 268
Reputation: Traicey is an unknown quantity at this point 
Solved Threads: 19
Traicey's Avatar
Traicey Traicey is offline Offline
Posting Whiz in Training

Re: Some Error Please help

 
0
  #7
Jun 20th, 2009
I have this code now but its complaining about the string not in a correct format

  1. string lid = "";
  2. //its conplaining about this line int loanid = int.Parse(lid)
  3. int loanid = int.Parse(lid);
  4.  
  5. string stringConn = "Data source=127.0.0.1; user id=*********; Password=*************;";
  6.  
  7. OracleConnection conn = new OracleConnection(stringConn);
  8. conn.Open();
  9.  
  10. string sql = "Select LoanID, BookID, MemberID, LoanDate, ReturnDate, FineAmount, FinePaid where LoanID = + " loanid;
  11.  
  12. OracleCommand cmd = new OracleCommand(sql, conn);
  13. cmd.Parameters.add("LoanID", OracleType.Number, loanid);
  14. int ok = cmd.ExecuteNonQuery();
Last edited by Traicey; Jun 20th, 2009 at 11:37 am.
Some people get so rich they lose all respect for humanity. That's how rich I want to be.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 3,204
Reputation: sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of 
Solved Threads: 571
Sponsor
sknake's Avatar
sknake sknake is online now Online
.NET Enthusiast

Re: Some Error Please help

 
0
  #8
Jun 20th, 2009
What did you expect to happen? You're calling int.Parse() on an empty string:
  1. string lid = "";
  2. //its conplaining about this line int loanid = int.Parse(lid)
  3. int loanid = int.Parse(lid);

Here is functionally identical code:
  1. int i1 = int.Parse("");

Is "" a valid integer? No. What happens when you parse an invalid integer? An exception. What are you doing...?

try
  1. int loanId = 1000;

Then expand your code from there. You have not indicated where you are trying to pull this loan id from? Probably a querystring in the URL if its a site, or a lookup control on a form?
Scott Knake
Custom Software Development
Apex Software, Inc.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,612
Reputation: adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of 
Solved Threads: 463
Moderator
adatapost's Avatar
adatapost adatapost is offline Offline
Posting Maven

Re: Some Error Please help

 
0
  #9
Jun 21st, 2009
I think poster want to learn something but he/she doesnot know how to learn and where to learn?

>Do you know - SQL and PL (Structured Query Language and PL)?
No
Your select query answered this: (FROM clause is missing)
  1. string sql = "Select LoanID, BookID, MemberID, LoanDate,
  2. ReturnDate, FineAmount, FinePaid where LoanID =
  3. + " loanid;
>cmd.Parameters.add("LoanID", OracleType.Number, loanid); What
is this?
No need. Learn ADO.NET classes.
>int ok = cmd.ExecuteNonQuery();
Without opening a connection?

I am not discourage you. Either you are misleading us or you have a misconception.
Failure is not fatal, but failure to change might be. - John Wooden
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the ASP.NET Forum
Thread Tools Search this Thread



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

©2003 - 2009 DaniWeb® LLC