i want 2 pass values(enterd in textbox)to table in sql
server without using stored procedure in c#.plz tell me
code with an example.

Answer Posted / bala

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;


namespace WindowsFormsApplication4
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();

}

private void button1_Click(object sender, EventArgs
e)
{
String ConnectionString = "Data
Source=ServerName;Initial Catalog=DatabaseName;Integrated
Security=true";
String Query = "insert into tablename values('"
+ textBox1.Text + "')";
SqlConnection Con = new SqlConnection
(ConnectionString) ;
Con.Open();
SqlCommand Cmd = new SqlCommand(Query, Con);
Cmd.ExecuteNonQuery();
Cmd.Dispose();
Con.Close();

}
}
}

Is This Answer Correct ?    10 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the significance of CommandBehavior.CloseConnection ?

559


What are dcl commands?

502


What is ado.net objects?

514


Describe ado.net object model in detail.

527


What are three methods for displaying data in a syncfusion datagrid

606






What is bubbled event can you please explain?

520


What are the data providers used in ado.net

535


What are the different methods available under the sqlcommand class to access the data?

565


What is Serialization in .NET? what are the types of Serialization?

542


What is ado.net code?

512


What is execute scalar in ado.net?

492


What is basic use of data view?

503


What is the executescalar method?

576


Difference between sqlcommand and sqlcommandbuilder?

570


Which parameter of ConnectionString is used to specify the name of the database?

542