查看SQL表到DATAGRID. [英] View SQL Table to a DATAGRID.

查看:64
本文介绍了查看SQL表到DATAGRID.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发WindowsMo​​bile应用程序,我想连接到特定的数据库!执行查询后,在datagrid中查看表.我不能这样做,它什么也没有显示.请帮助
这是代码

I am developing a WindowsMobile application and I want to connect to a specific databse!Aafter executing the query,view the table in a datagrid.I cant do that,it doesnt show anything.Please HELP
here is the code

using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using System.Data.SqlServerCe;
using System.Data.SqlClient;
using System.IO;
using System.Text.RegularExpressions;

namespace WINDOWS_CE
{
    public partial class subForm2 : Form
    {

        public subForm2()
        {
            InitializeComponent();
        }
        private void subForm2_Load(object sender, EventArgs e)
        {
        }

        private void dataGrid1_CurrentCellChanged(object sender, EventArgs e)
        {
            string _connectionstring = @"Data Source=endripc/sql2005;initial catalog=ABCOM;user id=sa;password=;";
            SqlConnection _connection = new SqlConnection(_connectionstring);
            _connection.Open();
            string _sql = "SELECT * FROM [ARTIKUJ]";
            SqlCommand _command = new SqlCommand(_sql, _connection);
            SqlDataAdapter _adapter = new SqlDataAdapter(_command);
            

            DataTable _table = new DataTable();
            _adapter.Fill(_table);

            dataGrid1.DataSource = _table;
            _connection.Close();
        }
    }

}

推荐答案

I Suggest not to use * Asterisk
You must specify the fields of your Select Statement





/*For Example*/

Select 
      [STATMENT_ID] 
      [SortCode] 
      [AccountNumber] 
      [Bank_Ref] 
      [AccountName] 
      [Currency] 
      [AccountType] 
      [BankID] 
      [BankName] 
      [Date] 
      [Narrative1] 
      [Type] 
      [Debit] 
      [Credit] 
      [isreconsile]
     From 
         ARTIKUJ



请投票或接受解决方案
如果这对您有帮助
谢谢



Please Vote or Accept Solution
If this will Help you
Thanks


一切都很好,问题出在设备仿真器上,它无法连接到数据库,因为它可以在Windows窗体中正常工作!!
Everything was ok,the problem is with the device emulator,it fails to connect to the db,as it works well in windows form!!


这篇关于查看SQL表到DATAGRID.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆