PDA

View Full Version : دیتا گرید ویو



asroushi
یک شنبه 14 دی 1393, 09:34 صبح
دوستان من کد زیر را در لود فرم می نویسیم ولی اطلاعاتی در دیتا گرید ویو نمایش نمی دهد خواهشا کمک کنید .هدف نمایش اطلاعات یک جدول در دیتا گرید ویو با کد نویسی می باشد
Dim rs As DataSet
Dim cn As SqlConnection
Dim cmd As SqlCommand
Dim adp As SqlDataAdapter
cn = New SqlConnection("Data Source=AHA-PC;Initial Catalog=student;Integrated Security=True")


cn.Open()
cmd = New SqlCommand("select * from daneshjo", cn)
adp.SelectCommand = cmd
adp.Fill(rs)
DataGridView1.DataSource = rs.Tables(1)
adp.Update(rs)
cn.Close()

kiadata
دوشنبه 22 دی 1393, 13:00 عصر
سلام فکر کنم نحوه مقدار دادنتون به دیتا سورس مشکل داره من VB کار نکردم اما نمونه کد سی شارپشو براتون میذارم شاید بتونه کمکتون کنه.


C# program that uses SqlCeConnection

using System.Data;
using System.Data.SqlServerCe;
using System.Windows.Forms;

namespace WindowsFormsApplication5
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
FillData();
}

void FillData()
{
// 1
// Open connection
using (SqlCeConnection c = new SqlCeConnection(
Properties.Settings.Default.DataConnectionString))
{
c.Open();
// 2
// Create new DataAdapter
using (SqlCeDataAdapter a = new SqlCeDataAdapter(
"SELECT * FROM Animals", c))
{
// 3
// Use DataAdapter to fill DataTable
DataTable t = new DataTable();
a.Fill(t);
// 4
// Render data onto the screen
dataGridView1.DataSource = t;
}
}
}
} }

kiadata
دوشنبه 22 دی 1393, 13:04 عصر
امیدوارم که بتونه کمکی بکنه


string select = "SELECT * FROM tblEmployee";
Connection c = new Connection();
SqlDataAdapter dataAdapter = new SqlDataAdapter(select, c.con); //c.con is the connection string

SqlCommandBuilder commandBuilder = new SqlCommandBuilder(dataAdapter);
DataSet ds = new DataSet();
dataAdapter.Fill(ds);
dataGridView1.ReadOnly = true;
dataGridView.DataSource = ds.tables[0];