Lost Password?

Go Back   CodeCall Programming Forum > Web Development Forum > Database & Database Programming

Unregistered, Check out the Coder Battles in the Announcement and Game forums.

Database & Database Programming MySQL, Oracle, SQL, PL/SQL, ABAP, Smart Forms, and other databases and languages. A database is an organized body of related information used in many websites (including CC).

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-25-2006, 07:56 PM
encoder encoder is offline
Learning Programmer
 
Join Date: Apr 2006
Posts: 40
Credits: 0
Rep Power: 9
encoder is on a distinguished road
Default MS Access Problem

I got a friend who got a problem in MS Access. Hope someone could help answering this question then I would tell him how to do it.

How can you put a value into a variable in the database? He wants to put the value inserted in the textbox and then store it in the database.

Here's his code, is this correct?

insert into tablename values (txtbox.text)

But this didn't work.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 05-28-2006, 08:39 AM
NeedHelp NeedHelp is offline
Programming God
 
Join Date: May 2006
Posts: 527
Credits: 0
Rep Power: 12
NeedHelp is on a distinguished road
Default

That should work just fine. What programming language is he using?

For PHP it would look like this

Code:
$query = "INSERT INTO tablename VALUES ('$variable')";
$results = mysql_query($query);
__________________
I Need Help
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 06-12-2006, 10:56 AM
dirkfirst dirkfirst is offline
Programming Professional
 
Join Date: May 2006
Posts: 338
Credits: 0
Rep Power: 11
dirkfirst is on a distinguished road
Default

What error does he receive? That should work just fine as a query.
__________________
DirkFirst
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 06-13-2006, 02:51 PM
NeedHelp NeedHelp is offline
Programming God
 
Join Date: May 2006
Posts: 527
Credits: 0
Rep Power: 12
NeedHelp is on a distinguished road
Default

That is his SQL query - what is his actual C# Code?????
__________________
I Need Help
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 06-13-2006, 02:57 PM
NeedHelp NeedHelp is offline
Programming God
 
Join Date: May 2006
Posts: 527
Credits: 0
Rep Power: 12
NeedHelp is on a distinguished road
Default

Here is C# code for INSERT:
Code:
string sqlIns = "INSERT INTO table (name, information, other) VALUES (@name, @information, @other)";

db.Open();
try
{
     SqlCommand cmdIns = new SqlCommand(sqlIns, db.Connection);
     cmdIns.Parameters.Add("@name", info);
     cmdIns.Parameters.Add("@information", info1);
     cmdIns.Parameters.Add("@other", info2);
     cmdIns.ExecuteNonQuery();
     cmdIns.Dispose();
     cmdIns = null;
}
catch(Exception ex)
{
     throw new Exception(ex.ToString(), ex);
}
finally
{
     db.Close();
}
__________________
I Need Help
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #6 (permalink)  
Old 07-04-2006, 08:55 AM
brackett brackett is offline
Programmer
 
Join Date: May 2006
Posts: 193
Credits: 0
Rep Power: 10
brackett is on a distinguished road
Default

Looks like you're using the SqlClient libraries, but you said you're inserting into Access? You need to use the OLEDB libraries (OleDbCommand, OleDbConnection, etc.) for that.

As an aside, there's no reason to throw a new exception if you're not changing anything - all you're doing is screwing up the stack trace making debugging a lot harder (at least you kept the innerException though). Since you're also throwing a generic Exception, it'll be difficult to catch further up the stack. You should either (a) get rid of the catch (it's not required to have a catch in a try statement) which will let the actual exception bubble up the stack, (b) derive your own exception class and wrap the exception in it, or (c) log it and just put throw; which will just let the exception bubble up without clobbering the stack trace.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Peculiar UI Problem Needs Tackling adriyel C# Programming 2 04-06-2008 07:46 AM
i have a problem please help me!!!???? stack Java Help 8 09-22-2007 03:17 PM
Access server file from client ahpooh Visual Basic Programming 1 09-06-2007 01:36 PM
[PHP] Faking Shell Access Through PHP pranky PHP Tutorials 2 03-29-2007 06:28 AM
Java:Tutorial - Access Modifiers John Java Tutorials 0 12-09-2006 09:57 AM


All times are GMT -5. The time now is 04:55 AM.

Contest Stats

Xav ........ 1097.16
MeTh0Dz|Reb0rn ........ 986.37
morefood2001 ........ 850.04
John ........ 841.93
WingedPanther ........ 684.54
marwex89 ........ 638.26
Brandon W ........ 493.36
chili5 ........ 292.12
Steve.L ........ 188.37
orjan ........ 187.41

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 79%

Ads