回复 2楼 跳过去
谢谢!还有一个问题。怎么能将数据库里的数据在gridview中显示,我们调试的时候没有错,可是显示不出结果,gridview里是空的,连表格都不出,下面是我们的代码。
using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace all
{
public partial class shop : Form
{
public shop()
{
InitializeComponent();
this.IsMdiContainer = true;
}
SqlDataAdapter sqlDataAdapter;
DataSet abc;
private void shop_Load(object sender, EventArgs e)
{
SqlConnection myConnection = new SqlConnection();
myConnection.ConnectionString = "server=PC-20111126CNWU;uid=sa;pwd=123;database=store";
SqlCommand sqlCommand = new SqlCommand();
sqlCommand.Connection = myConnection;
= CommandType.Text;
= "SELECT sno as 编号,name as 店名,time as 经营时间,star as 星级指数 from shop1";
sqlDataAdapter = new SqlDataAdapter();
sqlDataAdapter.SelectCommand = sqlCommand;
SqlCommandBuilder builder = new SqlCommandBuilder(sqlDataAdapter);
abc = new DataSet();
sqlDataAdapter.Fill(abc, "shop1");
dataGridView1.DataSource = abc;
dataGridView1.DataMember = "shop1";
}
}
}