943,836 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Unsolved
  • Views: 598
  • ASP.NET RSS
Jun 20th, 2009
0

Some Error Please help

Expand Post »
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

C# Syntax (Toggle Plain Text)
  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();
Similar Threads
Reputation Points: 26
Solved Threads: 19
Posting Whiz in Training
Traicey is offline Offline
283 posts
since Mar 2008
Jun 20th, 2009
0

Re: Some Error Please help

Your syntax should be:
sql Syntax (Toggle Plain Text)
  1. INSERT INTO Table (Col1, Col2, Col3)
  2. SELECT Col1, Col2, Col3
  3. FROM SomeOtherTable
Featured Poster
Reputation Points: 1749
Solved Threads: 735
Senior Poster
sknake is offline Offline
3,948 posts
since Feb 2009
Jun 20th, 2009
0

Re: Some Error Please help

I dont think I understand what ur trying to say can u elaborarte a bit,

Thanks
Reputation Points: 26
Solved Threads: 19
Posting Whiz in Training
Traicey is offline Offline
283 posts
since Mar 2008
Jun 20th, 2009
0

Re: Some Error Please help

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:
c# Syntax (Toggle Plain Text)
  1. sql += " INTO('" + lid + "', '" + bid + "', '" ....
Evaluates to:
c# Syntax (Toggle Plain Text)
  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)
sql Syntax (Toggle Plain Text)
  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:
c# Syntax (Toggle Plain Text)
  1. string lid = "";
  2. string bid = "";
  3. string mid = "";
  4. string ldate = "";
  5. string rdate = "";
  6. string famount = "";
  7. string fpaid = "";
Featured Poster
Reputation Points: 1749
Solved Threads: 735
Senior Poster
sknake is offline Offline
3,948 posts
since Feb 2009
Jun 20th, 2009
0

Re: Some Error Please help

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.
Reputation Points: 26
Solved Threads: 19
Posting Whiz in Training
Traicey is offline Offline
283 posts
since Mar 2008
Jun 20th, 2009
0

Re: Some Error Please help

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:
c# Syntax (Toggle Plain Text)
  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
Featured Poster
Reputation Points: 1749
Solved Threads: 735
Senior Poster
sknake is offline Offline
3,948 posts
since Feb 2009
Jun 20th, 2009
0

Re: Some Error Please help

I have this code now but its complaining about the string not in a correct format

C# Syntax (Toggle Plain Text)
  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.
Reputation Points: 26
Solved Threads: 19
Posting Whiz in Training
Traicey is offline Offline
283 posts
since Mar 2008
Jun 20th, 2009
0

Re: Some Error Please help

What did you expect to happen? You're calling int.Parse() on an empty string:
c# Syntax (Toggle Plain Text)
  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:
c# Syntax (Toggle Plain Text)
  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
c# Syntax (Toggle Plain Text)
  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?
Featured Poster
Reputation Points: 1749
Solved Threads: 735
Senior Poster
sknake is offline Offline
3,948 posts
since Feb 2009
Jun 21st, 2009
0

Re: Some Error Please help

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)
C# Syntax (Toggle Plain Text)
  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.
Moderator
Reputation Points: 2136
Solved Threads: 1228
Posting Genius
adatapost is offline Offline
6,527 posts
since Oct 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: what do you know what is software
Next Thread in ASP.NET Forum Timeline: url rewrite problem





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC