problem with dataGridViewand XML
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();
}.
Re: problem with dataGridViewand XML
Do you want to Display this in a Gridview(ASP.NET) or Win App?
if you want to Display this in the ASP.NET or Win App you do the Gridview you need to Supply a Datamember "Name of the Datatable". And if this is a Web App you need to call the DataBind method to Bind the Grid to the Page