How to create dynamically create table add to db records
hi
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Satyapriya NayakRank #47 · 31.5K reputationPosted Jun 18, 2014, 1:54 AM EDT
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");
}
}
}
}