•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the MySQL section within the Web Development category of DaniWeb, a massive community of 427,935 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,936 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our MySQL advertiser: Programming Forums
Views: 1051 | Replies: 5
![]() |
•
•
Join Date: Jun 2008
Posts: 3
Reputation:
Rep Power: 0
Solved Threads: 0
i was just doing a simple thing in C#, just trying to put the values feeded in the text boxes in sql database. i am giving the code below the code executed perfectly but when i went to look into the table data there was no data inserted...... pls HELP...!!!
at the end i get the message in the message box "inserted successfully" but there is no value inserted in the table....
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Data.Sql;
namespace txtbox
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
SqlConnection cn=new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\Details.mdf;Integrated Security=True;User Instance=True");
string sql = " INSERT into employee(fname, mname, lname) VALUES (@fname, @mname,@lname)";
SqlCommand cmd = new SqlCommand(sql, cn);
cmd.Parameters.Add(new SqlParameter("@fname", SqlDbType.NVarChar,50));
cmd.Parameters.Add(new SqlParameter("@mname", SqlDbType.NVarChar,50));
cmd.Parameters.Add(new SqlParameter("@lname", SqlDbType.NVarChar,50));
cmd.Parameters[0].Value = textBox1.Text;
cmd.Parameters[1].Value = textBox2.Text;
cmd.Parameters[2].Value = textBox3.Text;
cn.Open();
cmd.ExecuteNonQuery();
MessageBox.Show("inserted successfully");
}
}
}•
•
Join Date: Dec 2007
Posts: 114
Reputation:
Rep Power: 1
Solved Threads: 14
String values must be enclosed with single quotes e.g.
You may try similar to this
INSERT into employee(fname, mname, lname) VALUES ('name', 'mname','name')You may try similar to this
string sql = " INSERT into employee(fname, mname, lname) VALUES ('@fname', '@mname','@lname')";•
•
Join Date: Jun 2008
Posts: 3
Reputation:
Rep Power: 0
Solved Threads: 0
•
•
•
•
String values must be enclosed with single quotes e.g.
INSERT into employee(fname, mname, lname) VALUES ('name', 'mname','name')
You may try similar to this
string sql = " INSERT into employee(fname, mname, lname) VALUES ('@fname', '@mname','@lname')";
Still not able to insert values into database table ....
whts the problem i cant figure it out ....
kindly help
•
•
Join Date: Jul 2008
Location: Sweet India
Posts: 849
Reputation:
Rep Power: 2
Solved Threads: 74
please once try this:
string sql = " INSERT into `employee`(`fname`, `mname`,` lname`) VALUES (@fname, @mname,@lname)";
Be intelligent, But Don't try to cheat.. Be innocent But Don't get cheated..
•
•
Join Date: Jun 2008
Posts: 3
Reputation:
Rep Power: 0
Solved Threads: 0
•
•
•
•
please once try this:
string sql = " INSERT into `employee`(`fname`, `mname`,` lname`) VALUES (@fname, @mname,@lname)";
i knew this wont work but gave it a try ..... it still does not solves the problem
•
•
Join Date: Dec 2004
Location: London or Slovakia
Posts: 2,467
Reputation:
Rep Power: 11
Solved Threads: 296
@mridatrix - your coding is wrong. Database connectivity in any programming language is always associated with try & catch block often accompanied by final . Something similar to this example
c# Syntax (Toggle Plain Text)
try { conn.Open(); cmd.ExecuteNonQuery(); } catch (SqlException ex) { errorMessage(); } finally { conn.Close(); // Just simple notification DialogResult result = MessageBox.Show("New book added to database", "Database Message", MessageBoxButtons.OK, MessageBoxIcon.Information, 0, 0); }
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)
If we helped you to solve your problem, answered your question please mark your post as SOLVED.
Publilius Syrus
(~100 BC)
If we helped you to solve your problem, answered your question please mark your post as SOLVED.
![]() |
•
•
•
•
•
•
•
•
DaniWeb MySQL Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
age amd avatar backup blue gene breach business chips daniweb data data protection database development dos economy energy enterprise europe government hacker hardware hp ibm ibm. news intel ibm it linux medicine memory microsoft news open source openoffice pc ps3 recession red hat russia security server sql sun supercomputer supercomputing survey technology trends ubuntu working x86
- MSSql 2000 Unable to insert into database (MS SQL)
- submiting info into a database for retrieval! (PHP)
- Unable to insert data into database. (MySQL)
- How to Hash and Store in Database (ASP.NET)
- Unable to insert data into SQL Database (ASP)
- Unable to insert form data into a database (ASP)
- mySQL database searching for registration (MySQL)
- php wont submit data into the database (PHP)
Other Threads in the MySQL Forum
- Previous Thread: Best way to query
- Next Thread: sql query



Linear Mode