Hi,
Im facing a weird problem. I am just adding a DataGridView control to my program's interface. Then I am passing the Form1.cs then wanna write some codes with this control but VS can not see this control. I mean can not identify. All codes below ;
------------------------------------
private void button1_Click(object sender, EventArgs e)
{
string query = "Data Source=1.1.1.1;Initial Catalog=mdb;User Id=user;Password=qweasd;";
SqlConnection conn = new SqlConnection(query);
conn.Open();
DataTable data_table = new DataTable();
SqlDataAdapter sql_adapter = new SqlDataAdapter("SELECT * FROM table", conn);
sql_adapter.Fill(data_table);
datagridview1.Fill ...... --> I cant fill dataadapter to gridview..
------------------------------------
Loading
VulpesPosted Jan 9, 2012, 5:09 AM
AartiPosted Jan 9, 2012, 3:03 AM
string strCon = "Data Source=dbServer;Initial Catalog=testDB;Integrated Security=True";
string strSQL = "select * from table1";
SqlDataAdapter dataAdapter = new SqlDataAdapter(strSQL, strCon);
SqlCommandBuilder commandBuilder = new SqlCommandBuilder(dataAdapter);
// Populate a new data table and bind it to the BindingSource.
DataTable table = new DataTable();
table.Locale = System.Globalization.CultureInfo.InvariantCulture;
dataAdapter.Fill(table);
dbBindSource.DataSource = table;
// Resize the DataGridView columns to fit the newly loaded content.
dbGridView.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader);
// you can make it grid readonly.
dbGridView.ReadOnly = true;
// finally bind the data to the grid
dbGridView.DataSource = dbBindSource;
true;// finally bind the data to the grid
dbGridView.DataSource = dbBindSource;
Satyapriya NayakPosted Jan 9, 2012, 2:45 AM
using System.Data.SqlClient;
string ConnectionString = System.Configuration.ConfigurationSettings.AppSettings["dsn"];
SqlCommand com;
SqlDataAdapter oda;
string str;
private void button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(ConnectionString);
DataTable dataTable = new DataTable();
com = new SqlCommand();
com.Connection = con;
con.Open();
com.CommandText = "Select * from tablename";
oda = new SqlDataAdapter(com);
oda.Fill(dataTable);
con.Close();
dataGridView1.DataSource = dataTable;
}
Thanks
Satyapriya NayakPosted Jan 9, 2012, 2:41 AM
Try this...
OleDbConnection con = new OleDbConnection(ConnectionString);
con.Open();
str = "select * from customer";
com = new OleDbCommand(str, con);
oda = new OleDbDataAdapter(com);
ds = new DataSet();
oda.Fill(ds, "customer");
dataGridView1.DataMember = "customer";
dataGridView1.DataSource = ds;
con.Close();
Thanks
yokzuPosted Jan 9, 2012, 2:37 AM
dataGridView1.DataSource = data_table;
But VS has not recognize "dataGridView1".. I mean its not auto complete.. Not coloured.