how to create dynamically create table add to db records
hi
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Satyapriya NayakPosted Jun 18, 2014, 5:54 AM
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
{
SqlConnection con = new SqlConnection(@"server = HOME-A81E14F1B4/SQLEXPRESS;data source = .; initial catalog = test; user id=sa;pwd =pintu ;integrated security = SSPI");
SqlCommand com;
string str;
public Form1()
{
InitializeComponent();
}
private void btn_create_Click(object sender, EventArgs e)
{
str = "CREATE TABLE employee (name VARCHAR(50),address VARCHAR(50))";
com = new SqlCommand(str, con);
try
{
con.Open();
com.ExecuteNonQuery();
}
catch { }
con.Close();
MessageBox.Show("Table Created");
}
private void btn_insert_Click(object sender, EventArgs e)
{
try
{
con.Open();
com = new SqlCommand("Insert into employee values('Raj','Pune')", con);
com.ExecuteNonQuery();
con.Close();
}
catch { }
{
MessageBox.Show("Record inserted");
}
}
}
}