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 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?
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
> 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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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')"...
|
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...
|
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>
...
|
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.
...
|
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...
|
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...
|
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"...
|
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...
|
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) {
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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...
|
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,...
|
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...
|
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...
|
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...
|
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,...
|
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...
| |