|
||||||
| 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). |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||
|
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. |
| Sponsored Links |
|
|
|
|||
|
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 |
|
|||
|
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 |
| Sponsored Links |
|
|
|
|||
|
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. |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
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 |
| John | ........ | 223.00000 |
| dargueta | ........ | 168.00000 |
| Xav | ........ | 164.00000 |
| gaylo565 | ........ | 18.00000 |
| WingedPanther | ........ | 15.00000 |
| |pH| | ........ | 15.00000 |
| Johnnyboy | ........ | 3.00000 |
| navghost | ........ | 1.00000 |
Goal: 100,000 Posts
Complete: 66%