Click here to Skip to main content
15,889,872 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
C#
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();
        }
    }

}
Posted
Updated 9-Feb-12 0:41am
v2

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


SQL
/*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
 
Share this answer
 
Comments
IviKAZAZI 9-Feb-12 7:13am    
No it doesn't work.Still the same.but thanx
Everything was ok,the problem is with the device emulator,it fails to connect to the db,as it works well in windows form!!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900