473,398 Members | 2,125 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Insert string into database

hi,

how can I solve this problem? should I write some code or this is provided
by Microsoft?

string FirstName = "Monica";
string Number = "123456789";

strCommand = "INSERT INTO Profiles (FirstName, LastName) " +
"VALUES (FirstName, Number)";
.............................................

thisCommand.ExecuteNonQuery();

there are some problem in strCommand. please tell me what's the problem.

thank you,
Monica

Mar 2 '07 #1
3 3473
string FirstName = "Monica";
string Number = "123456789";

strCommand = "INSERT INTO Profiles (FirstName, LastName) " +
"VALUES (FirstName, Number)";
............................................

thisCommand.ExecuteNonQuery();
how about this:

strCommand = string.Format("INSERT INTO Profiles (FirstName,
LastName) VALUES ('%s', '%s')", FirstName, Number);

That's assuming your Number field is really a string field.

Mar 2 '07 #2
On Mar 1, 7:46 pm, Monica <Mon...@discussions.microsoft.comwrote:
hi,

how can I solve this problem? should I write some code or this is provided
by Microsoft?

string FirstName = "Monica";
string Number = "123456789";

strCommand = "INSERT INTO Profiles (FirstName, LastName) " +
"VALUES (FirstName, Number)";
............................................

thisCommand.ExecuteNonQuery();

there are some problem in strCommand. please tell me what's the problem.

thank you,
Monica
I think you want to try this command string

strCommand = "INSERT INTO Profiles (FirstName, LastName) Values (" +
FirstName + ", " + Number + ")";

I think this will solve your problem but to be sure I would need to
know a little about the design of the table and more of your source
code (connection string, connecting, etc.). Try posting some code
information if it doesn't work.

Mar 2 '07 #3
Monica <Mo****@discussions.microsoft.comwrote:
how can I solve this problem? should I write some code or this is provided
by Microsoft?

string FirstName = "Monica";
string Number = "123456789";

strCommand = "INSERT INTO Profiles (FirstName, LastName) " +
"VALUES (FirstName, Number)";
............................................

thisCommand.ExecuteNonQuery();

there are some problem in strCommand. please tell me what's the problem.
You should write this as a parameterised command, and add the parameter
values to the command. That way you avoid SQL injection attacks.

See http://pobox.com/~skeet/csharp/faq/#db.parameters

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Mar 2 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Michel R. | last post by:
What`s wrong with this ??? The insert does not add into the database. Using a Winform and Database is sc.mdb Filename is supplier Fields SuppNbr Int64 SuppName String SuppPhone Int64...
7
by: kosta | last post by:
hello! one of my forms communicates with a database, and is supposed to add a row to a table using an Insert statement... however, I get a 'oledb - syntax error' exception... I have double...
3
by: alexmaster_2004 | last post by:
hi i have made an application using C# that access sql2000. this application is just used to insert data to the database. i use something like this in my code: // string colmnA = TextBox1.Text;...
3
by: Hai Nguyen | last post by:
Hi all I was attempting to insert multiple row by using a loop into a database.A table has 2 primary keys and one regular field (PR) (PR) ID Project Ans 1 2 a 1 ...
20
by: Guadala Harry | last post by:
In an ASCX, I have a Literal control into which I inject a at runtime. litInjectedContent.Text = dataClass.GetHTMLSnippetFromDB(someID); This works great as long as the contains just...
3
by: Shapper | last post by:
Hello, I have created 3 functions to insert, update and delete an Access database record. The Insert and the Delete code are working fine. The update is not. I checked and my database has all...
0
by: Eustice Scrubb | last post by:
In line coding problem. Here's my code: <script language="VB" runat="server"> Dim myConnection As SqlConnection Sub Page_Load(Src As Object, e As EventArgs) ' Create a connection to the SQL...
7
by: David Bear | last post by:
I have a dictionary that contains a row of data intended for a data base. The dictionary keys are the field names. The values are the values to be inserted. I am looking for a good pythonic...
7
by: Kevin Lawrence | last post by:
Hi all I want to do "INSERT INTO Table (Blob) Values('blobdataasstring')". ...rather than using the parameter driven method, is it possible? And if so what encoder do I use to convert the...
6
by: rn5a | last post by:
During registration, users are supposed to enter the following details: First Name, Last Name, EMail, UserName, Password, Confirm Password, Address, City, State, Country, Zip & Phone Number. I am...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.