473,404 Members | 2,137 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,404 software developers and data experts.

MySql Insert what am I doing wrong?

Hi,

I am using a Mysql Database with c# and I am trying to insert a record in
my table. My code is as follows.

MySqlConnection mySqlConnection = new MySqlConnection("Network
Address=localhost;Initial Catalog='test'; User
Name='root';Password='tottenham'");
//
MySqlCommand mySqlCommand = new MySqlCommand("",mySqlConnection);
mySqlCommand.CommandText = "insert into users (login,name,password) values
(@sLogin,@sName,@sPassword)";
mySqlCommand.Parameters.Add("@sLogin",MySqlDbType. VarChar,45);
mySqlCommand.Parameters.Add("@sName",MySqlDbType.V arChar,150);
mySqlCommand.Parameters.Add("@sPassword",MySqlDbTy pe.VarChar,15);
//
mySqlCommand.Parameters["@sLogin"].Value = "ivan-edp";
mySqlCommand.Parameters["@sName"].Value = "Ivan";
mySqlCommand.Parameters["@sPassword"].Value = "abc";
//
mySqlConnection.Open();
mySqlCommand.ExecuteNonQuery();
mySqlConnection.Close();

But somehow the value I am passing in the paramters is not going and in the
table I am always ending with a record filled with null values.

Any idea?
Ivan
May 10 '06 #1
3 11174
"Ivan Sammut" <sa*****@hotmail.com> wrote in message
news:eJ**************@TK2MSFTNGP04.phx.gbl...
MySqlConnection mySqlConnection = new MySqlConnection("Network
Address=localhost;Initial Catalog='test'; User
Name='root';Password='tottenham'");
I hope that's not your real password - this is a public newsgroup, you
know... :-)
MySqlCommand mySqlCommand = new MySqlCommand("",mySqlConnection);
mySqlCommand.CommandText = "insert into users (login,name,password) values
(@sLogin,@sName,@sPassword)";
mySqlCommand.Parameters.Add("@sLogin",MySqlDbType. VarChar,45);
mySqlCommand.Parameters.Add("@sName",MySqlDbType.V arChar,150);
mySqlCommand.Parameters.Add("@sPassword",MySqlDbTy pe.VarChar,15);
//
mySqlCommand.Parameters["@sLogin"].Value = "ivan-edp";
mySqlCommand.Parameters["@sName"].Value = "Ivan";
mySqlCommand.Parameters["@sPassword"].Value = "abc";
//
mySqlConnection.Open();
mySqlCommand.ExecuteNonQuery();
mySqlConnection.Close();

But somehow the value I am passing in the paramters is not going and in
the
table I am always ending with a record filled with null values.

Any idea?


1) ExecuteNonQuery() returns an int representing the number of records
affected by the SQL - what does it return in your case?

2) Replace your parameters temporarily with hard-coded values e.g. "insert
into users (login,name,password) values ('ivan-edp','Ivan','abc')"; - what
happens then?

3) Are you getting any errors?

4) Amend your table definition so that the three fields in question are not
nullable - what happens then?

5) Run your SQL statement against MySQL directly through your front-end
software (e.g. Navicat) - what happens then?
May 10 '06 #2
Can the MySql provider take named parameters?

Try replacing your parameter usage with ordinal positions and see what
happens.

- Colin

"Ivan Sammut" <sa*****@hotmail.com> wrote in message
news:eJ**************@TK2MSFTNGP04.phx.gbl...
Hi,

I am using a Mysql Database with c# and I am trying to insert a record in my table. My code is as follows.

MySqlConnection mySqlConnection = new MySqlConnection("Network
Address=localhost;Initial Catalog='test'; User
Name='root';Password='tottenham'");
//
MySqlCommand mySqlCommand = new MySqlCommand("",mySqlConnection);
mySqlCommand.CommandText = "insert into users (login,name,password) values
(@sLogin,@sName,@sPassword)";
mySqlCommand.Parameters.Add("@sLogin",MySqlDbType. VarChar,45);
mySqlCommand.Parameters.Add("@sName",MySqlDbType.V arChar,150);
mySqlCommand.Parameters.Add("@sPassword",MySqlDbTy pe.VarChar,15);
//
mySqlCommand.Parameters["@sLogin"].Value = "ivan-edp";
mySqlCommand.Parameters["@sName"].Value = "Ivan";
mySqlCommand.Parameters["@sPassword"].Value = "abc";
//
mySqlConnection.Open();
mySqlCommand.ExecuteNonQuery();
mySqlConnection.Close();

But somehow the value I am passing in the paramters is not going and in the table I am always ending with a record filled with null values.

Any idea?
Ivan

May 10 '06 #3
> Hi,

I am using a Mysql Database with c# and I am trying to insert a record in
my table. My code is as follows.

MySqlConnection mySqlConnection = new MySqlConnection("Network
Address=localhost;Initial Catalog='test'; User
Name='root';Password='tottenham'");
//
MySqlCommand mySqlCommand = new MySqlCommand("",mySqlConnection);
mySqlCommand.CommandText = "insert into users (login,name,password) values
(@sLogin,@sName,@sPassword)";
mySqlCommand.Parameters.Add("@sLogin",MySqlDbType. VarChar,45);
mySqlCommand.Parameters.Add("@sName",MySqlDbType.V arChar,150);
mySqlCommand.Parameters.Add("@sPassword",MySqlDbTy pe.VarChar,15);
//
mySqlCommand.Parameters["@sLogin"].Value = "ivan-edp";
mySqlCommand.Parameters["@sName"].Value = "Ivan";
mySqlCommand.Parameters["@sPassword"].Value = "abc";
//
mySqlConnection.Open();
mySqlCommand.ExecuteNonQuery();
mySqlConnection.Close();

But somehow the value I am passing in the paramters is not going and in the
table I am always ending with a record filled with null values.

Any idea?
Ivan


Are you sure you need a "@" in front of the parameter name? I had to
use a "?" instead to get parameters to work for MySql ...
Hans Kesting
May 10 '06 #4

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

Similar topics

4
by: Simom Thorpe | last post by:
Hi, I'm trying to insert a line into a MS access DB using ASP on IIS 5. This is the line: con.execute "INSERT INTO newProds(title,desc,catcode) VALUES ('Champagne Muff Scarf','','AC304B')"...
2
by: Aaron Ackerman | last post by:
I cannot a row to this bound DataGrid to SAVE MY LIFE! I have tried everything and I am at a loss. The using goes into add mode with the add button adds his data then updates with the update...
1
by: Miguel Dias Moura | last post by:
Hello, i added an ASP.Net input text form in a page: <td> <asp:TextBox ID="CV" Rows="15" runat="server" TextMode="MultiLine" Columns="66" ToolTip="Insert your CV" MaxLength="2000" /> </td> ...
2
by: David | last post by:
Hi, I have a MySQL database linked to an MS Access front-end. I have an app which works fine with the local copy of the Access DB, but when run with the linked tables for MySQL, it fails. ...
8
by: watkinsdev | last post by:
Hi, I have created a mesh class in visual studio 6.0 c++. I can create a device, render objects and can edit the objects by for instancnce selecting a cluster of vertices and processing the...
0
by: shapper | last post by:
Hello, I am creating a class with a control. I compiled the class and used it on an Asp.Net 2.0 web site page. I can see the begin and end tags of my control (<oland </ol>) but somehow the...
2
by: Tarik Monem | last post by:
OK! I've gone through a few tutorials and I cannot understand what I'm doing wrong casting_registration.php <table> <tr> <td> <form enctype="multipart/form-data" action="thankyou.php"...
9
by: tommurray | last post by:
Hi I am currently setting up a script so that it inserts information into one table and then follows onto the next few lines and checks to see if the user already has a row in a different table if...
10
by: DavidSeck.com | last post by:
Hi, I am working with the Facebook API right now, an I have kind of a problem, but I don't know what I am doing wrong. So I have a few arrays, f.ex.: User albums: array(2) {
2
Thekid
by: Thekid | last post by:
I'm having trouble getting my python scripts to insert into a mysql database. I'm able to do other commands successfully such as adding or dropping tables, selecting items from tables but inserting...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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 projectplanning, 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.