473,386 Members | 1,673 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,386 software developers and data experts.

my code is executing but data is not get inserted in table

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.Data.SqlClient;
  10.  
  11. namespace testing
  12. {
  13.     public partial class Form1 : Form
  14.     {
  15.         string connection=("Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\testing.mdf;Integrated Security=True;User Instance=True");
  16.         //string conn = System.Configuration.ConfigurationSettings.AppSettings["DBConn"];
  17.         SqlConnection con;
  18.         SqlCommand cmd;
  19.         string qry = "";
  20.         public Form1()
  21.         {
  22.             InitializeComponent();
  23.         }private void Form1_Load(object sender, EventArgs e)
  24.         {
  25.             // TODO: This line of code loads data into the 'testingDataSet1.testing' table. You can move, or remove it, as needed.
  26.             this.testingTableAdapter.Fill(this.testingDataSet1.testing);
  27.  
  28.         }
  29.  
  30.         private void button1_Click_1(object sender, EventArgs e)
  31.         {
  32. string first = textBox3 .Text ;  
  33.  
  34.              string last = textBox4 .Text ;  
  35.             qry = "insert into testing(col1,col2) values(@first,@last)";//('" +  textBox3 .Text  + "','" +  textBox4 .Text  + " ')";
  36.             con = new SqlConnection(connection);
  37.             cmd = new SqlCommand(qry, con);
  38.              cmd .Parameters.AddWithValue ("@first", first);  
  39.             cmd.Parameters.AddWithValue("@last", last);
  40.             cmd.Connection = con;
  41.             if (con.State == ConnectionState.Open)
  42.                 con.Close();
  43.             else
  44.                 con.Open();
  45.             cmd.ExecuteNonQuery();
  46.             con.Close();
  47.             MessageBox.Show("Recored is inserted");
  48.         }
Nov 7 '10 #1
1 1549
chech this version:

qry="insert into test(col1,col2) values ("+textbox3.text+","+textbox4.text+")"
cmd = new SqlCommand(qry,con);
cmd.ExecuiteNonQuery();

in my project this sample code nice work. i am not using Parametrs() metod in cmd.
Nov 7 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: JP SIngh | last post by:
Hi All I am trying to plot the days off employees have taken in the selected month visually using the following code. The code below takes a long time to execute typically about 8-15 secs each...
3
by: Andrus Moor | last post by:
To reproduce: run the following code in IE 6 and right-click in table. Observed result: Error : invalid argument at line var row = table.insertRow(0); Expected result: new row must be...
1
by: acharyaks | last post by:
Hi Guru, the aspx page code executing behind the controls and functions executing twice. How can I avoid running the code behind the controls (for example this vanishes the control box text...
8
by: Steve Jorgensen | last post by:
Hi folks, I'm posting this message because it's an issue I come up against relatively often, but I can't find any writings on the subject, and I haven't been able to figure out even what key...
4
by: Farraige | last post by:
Hi I need your help... I am implementing the method that updates given table (table is represented as list of lists of strings) according to other table (some kind of merging)... This method...
2
by: gaston | last post by:
Hi All I have three data bases with a table each one, what I want to do is to get the data from each table and insert it in a new data base table. The thing is that may be there is going to a...
1
by: Bob | last post by:
Hi all, I've designed a database that has an events table and an application table. Each event has an application associated with it and I've stored an application code in the events table then...
5
by: cheergurl | last post by:
i have a problem to display the data inserted at parent page.After i click a button submit at child page,the data that was inserted before are lost...can anybody give a solution to me how to remain...
2
by: shimul | last post by:
Hi, Have table with data ( like a,b,c,d in column 1), want to read data from table and put in text box in continuous form. like tble name "tbltest" and textbox name "txtbox". now want to...
1
by: digituf | last post by:
I have a form named:"RegistrationForm.php". when i click the "submit button", there's a data inserted in the database (the prove is, there a new row in the database), but there's no value from user...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...

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.