data not displayed in dataGridView but when i replace dataGridView by dataGrid it work ...why?
Code:SqlConnection sqlCon = new SqlConnection(); SqlCommand sqlCmd = new SqlCommand(); sqlCon.ConnectionString=@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Documents and Settings\Administrator\My Documents\ContactsDataBase.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"; sqlCmd.CommandText = "SELECT CustomerID,CustomerName FROM Customers FOR xml auto"; sqlCmd.Connection = sqlCon; try { sqlCon.Open(); XmlReader xmlReader = sqlCmd.ExecuteXmlReader(); DataSet ds = new DataSet(); ds.ReadXml(xmlReader, XmlReadMode.InferSchema); dataGridView1.DataSource = ds; } catch (SqlException) { MessageBox.Show("Error Occur"); } finally { sqlCon.Close(); }.




Reply With Quote