using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Data.SqlClient;
namespace WindowsFormsApplication2 { public partial class Form1 : Form { public Form1() { InitializeComponent(); }
private void Form1_Load(object sender, EventArgs e) { SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=I:\C3 soft\WindowsFormsApplication2\WindowsFormsApplication2\MTechSqlDatabase.mdf;Integrated Security=True;Connect Timeout=30"); SqlCommand cmd = new SqlCommand("Select * From UnitType",con ); SqlDataAdapter da = new SqlDataAdapter(cmd ); DataTable dt = new DataTable(); da.Fill(dt);
using System;
ReplyDeleteusing System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=I:\C3 soft\WindowsFormsApplication2\WindowsFormsApplication2\MTechSqlDatabase.mdf;Integrated Security=True;Connect Timeout=30");
SqlCommand cmd = new SqlCommand("Select * From UnitType",con );
SqlDataAdapter da = new SqlDataAdapter(cmd );
DataTable dt = new DataTable();
da.Fill(dt);
dataGridView1.AutoGenerateColumns = false;
dataGridView1.ColumnCount = 2;
dataGridView1.Columns[0].Name="UnitTypeID";
dataGridView1.Columns[0].HeaderText = "UnitTypeID";
dataGridView1.Columns[0].DataPropertyName = "UnitTypeID";
dataGridView1.Columns[1].Name = "UnitType";
dataGridView1.Columns[1].HeaderText = "UnitType";
dataGridView1.Columns[1].DataPropertyName = "UnitType";
dataGridView1.DataSource = dt;
}
}
}