我想从数据库中获取数据并在网格视图中显示 [英] i want to get the data from database and display in grid view
本文介绍了我想从数据库中获取数据并在网格视图中显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace grid
{
public partial class Form1 : Form
{
public DataTable dtRaw = new DataTable();
public Form1()
{
InitializeComponent();
//Fill.Data();
}
private void Form1_Load(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection("Server=KK-PC;Database=SampleDB;User id=sa;password=sa2008;");
string sql = "SELECT *FROM Emp_Details";
SqlCommand command = new SqlCommand(sql,conn);
command.Connection = conn;
DataTable data = new DataTable();
SqlDataAdapter Adapter = new SqlDataAdapter(command);
Adapter.Fill(data);
dataGridview.DataSource = data;
}
}
}
当我尝试执行此代码时,错误1当前上下文中不存在名称dataGridviewC:\ Users \KK \ Documents\Visual Studio 2010 \Projects\grid\grid\Form1.cs 37 16 grid发生。
任何人都可以帮我解决这个问题。
When i am trying to execute this code an "Error 1 The name 'dataGridview' does not exist in the current context C:\Users\KK\Documents\Visual Studio 2010\Projects\grid\grid\Form1.cs 37 16 grid" is occured.
Can any one help me to solve this issue.
推荐答案
http://www.aspdotnet-suresh.com/2011/02/how-to-inserteditupdate-and-delete-data.html [<一个href =http://www.aspdotnet-suresh.com/2011/02/how-to-inserteditupdate-and-delete-data.html\"target =_ blanktitle =新窗口> ^ ]
这可以帮助你....
http://www.aspdotnet-suresh.com/2011/02/how-to-inserteditupdate-and-delete-data.html[^]
This may Help you....
1。你可能已经删除了网格,或者它不存在。
2. conn.open()怎么样?你应该在获取记录之前打开sql连接;
1. You may have removed the grid or it wasn't there.
2. What about conn.open()? you should open the sql connection before fetching records;
参考:
http://www.dotnetperls.com/datagridview-tutorial [ ^ ]
http://www.dotnetfunda.com/forums/show/6337/how-to-bind-datagridview-in-windows-application-using-csharpnet [ ^ ]
这可能会有所帮助。
Refer:
http://www.dotnetperls.com/datagridview-tutorial[^]
http://www.dotnetfunda.com/forums/show/6337/how-to-bind-datagridview-in-windows-application-using-csharpnet[^]
This may help.
这篇关于我想从数据库中获取数据并在网格视图中显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文