dataset seems to be empty---wpftoolkit

Posted by Jayakumarkm under WPF on 4/4/2010 | Views : 1698 | Status : [Member] | Replies : 3
hi

im using windows appp wpf with c# .

dataset is empty for the code though my tble has value..


string connb = System.Configuration.ConfigurationSettings.AppSettings["anaMusical.Properties.Settings.anaConnectionString"].ToString();
SqlConnection conn = new SqlConnection(connb);
SqlCommand com;
string strSql = "SELECT * FROM anaMusical";


conn.Open();
com = new SqlCommand(strSql, conn);
SqlDataAdapter da = new SqlDataAdapter(com);

da.SelectCommand = com;
DataSet ds12 = new DataSet();

da.Fill(ds12, "anaMusical");
dataGrid4.DataContext = ds12;

//dataGrid4.ItemsSource = ds12.Tables[0].ToString();
conn.Close();
com.Dispose();




Responses

Posted by: Vuyiswamb on: 4/5/2010 [Member] [MVP] [Administrator] NotApplicable

Up
0
Down
change your code to this

string connb = System.Configuration.ConfigurationSettings.AppSettings["anaMusical.Properties.Settings.anaConnectionString"].ToString(); 

SqlConnection conn = new SqlConnection(connb);
SqlCommand com;
string strSql = "SELECT * FROM anaMusical";

com = new SqlCommand(strSql, conn);

SqlDataAdapter da = new SqlDataAdapter(com);

da.SelectCommand = com;

DataSet ds12 = new DataSet();

try
{
conn.Open();

da.Fill(ds12, "anaMusical");

if(ds12.tables[0].Rows.Count> 0) //check if your dataset has records
{
Datagrid.Datasource = ds12; //bind the grid
}
}
catch(sqlException ex)
{
finaly
{
conn.Close();
}


Thank you for posting at Dotnetfunda
[Administrator]

Jayakumarkm, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jayakumarkm on: 4/5/2010 [Member] Starter

Up
0
Down
hi,

now also my datagrid is empty...
what to do...
whether the conn string is correct..


Jayakumarkm, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vuyiswamb on: 4/7/2010 [Member] [MVP] [Administrator] NotApplicable

Up
0
Down
place a break point before the initialization of the connection string and check the value of the connection string. do you know how to do that ?

Thank you for posting at Dotnetfunda
[Administrator]

Jayakumarkm, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response