Гость
Целевая тема:
Создать новую тему:
Автор:
Форумы / WinForms, .Net Framework [игнор отключен] [закрыт для гостей] / Отображение данных в dataGrid из SQLCE / 4 сообщений из 4, страница 1 из 1
29.07.2004, 17:43
    #32627861
TaReN
Гость
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Отображение данных в dataGrid из SQLCE
В SQLCE устанвливаю свойство DataGrid1.DataSource=DataSet1; dataGrid остается пустой, хотя при таком выводе все записи показываются

foreach(DataRow dr in dt.Rows)
{
MessageBox.Show(string.Format("{0} {1} {2}",
dr["id"],dr["Vol"],dr["idmeter"]));
}

Что надо сделать для того чтобы dataGrid отображал данные dataSet из SQLCE?

-=<TaReN>=-
...
Рейтинг: 0 / 0
29.07.2004, 17:48
    #32627877
zass
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Отображение данных в dataGrid из SQLCE
А Fill(DataSet1) в _Load использовали?
...
Рейтинг: 0 / 0
29.07.2004, 18:40
    #32628006
wait
Гость
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Отображение данных в dataGrid из SQLCE
можно еще и вот так
using System;
using System.Drawing;
using System.Collections;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlServerCe;
using System.Data.Common;

namespace DataGrid
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.DataGrid dataGrid1;

//Declare the connection, DataAdapter, and DataSet.
private System.Data.SqlServerCe.SqlCeConnection sqlConn;
private System.Data.SqlServerCe.SqlCeDataAdapter sqlDA;
private System.Data.DataSet sqlDS;

public Form1()
{
//
// Required for Windows Form Designer support.
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//

try
{
sqlDS = new DataSet();

//It is assumed that there is a Sql Server CE database
//named test.sdf, and that the database has a table named
//People. These should be modified to fit your needs.
sqlConn = new SqlCeConnection("Data Source=test.sdf");

//Select everything from the People table.
sqlDA = new SqlCeDataAdapter("SELECT * FROM People", sqlConn);

//Fill the DataTable People within the DataSet.
sqlDA.Fill(sqlDS, "People");

//Set the DataSource to the People table in the DataSet.
dataGrid1.DataSource = sqlDS.Tables["People"];
}
catch (SqlCeException err)
{
//Add error handling code here.
}
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.dataGrid1 = new System.Windows.Forms.DataGrid();
//
// dataGrid1
//
this.dataGrid1.Location = new System.Drawing.Point(0, 16);
this.dataGrid1.Size = new System.Drawing.Size(240, 256);
this.dataGrid1.Text = "dataGrid1";
//
// Form1
//
this.Controls.Add(this.dataGrid1);
this.MinimizeBox = false;
this.Text = "DataGrid";

}
#endregion

/// <summary>
/// The main entry point for the application.
/// </summary>

static void Main()
{
Application.Run(new Form1());
}
}
}
...
Рейтинг: 0 / 0
30.07.2004, 08:44
    #32628430
TaReN
Гость
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Отображение данных в dataGrid из SQLCE
Да вместо "DataGrid1.DataSource=DataSet1;" написал с указанием конкретной таблицы "dataGrid1.DataSource = DataSet1.Tables["vol"];" и все заработало, а я думал что он из строки запроса поймет сам какую таблицу выводить

-=<TaReN>=-
...
Рейтинг: 0 / 0
Форумы / WinForms, .Net Framework [игнор отключен] [закрыт для гостей] / Отображение данных в dataGrid из SQLCE / 4 сообщений из 4, страница 1 из 1
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]