用C#编的火车时刻表查询系统

[复制链接]
查看11 | 回复2 | 2008-6-4 21:55:57 | 显示全部楼层 |阅读模式
连接数据库的代码我看不懂,请高手指点,我没学过怎样和数据库连接,但我做的课程设计需要数据库。谢谢最好能详细点!
string str="select ScheduleCode,TrainType,fromCity,toCity,LeaveTime,ArrivalTime,Distance,Days from T_Schedule";
string str1="select * from T_Schedule_Detail";
SqlDataAdapter sda=new SqlDataAdapter();
sda.SelectCommand=new SqlCommand(str,con);
sda.Fill(ds,"T_Schedule");
sda.FillSchema(ds,SchemaType.Mapped);
SqlDataAdapter sda1=new SqlDataAdapter();
sda1.SelectCommand=new SqlCommand(str1,con);
sda1.Fill(ds,"T_Schedule_Detail");
sda1.FillSchema(ds,SchemaType.Mapped);

DataGridTableStyle dts = new DataGridTableStyle();

dts.MappingName = "T_Schedule";

this.dataGrid1.TableStyles.Add(dts);

DataGridTableStyle dts1= new DataGridTableStyle();

dts.MappingName = "T_Schedule_Detail";

this.dataGrid2.TableStyles.Add(dts1);

回复

使用道具 举报

千问 | 2008-6-4 21:55:57 | 显示全部楼层
//查询语句,查询T_Schedule表中cheduleCode,TrainType,fromCity,toCity,LeaveTime,ArrivalTime,Distance,Days的内容
string str = "select ScheduleCode,TrainType,fromCity,toCity,LeaveTime,ArrivalTime,Distance,Days from T_Schedule";
//查询语句,查询T_Schedule_Detai表中的内容
string str1 = "select * from T_Schedule_Detail";
回复

使用道具 举报

千问 | 2008-6-4 21:55:57 | 显示全部楼层
直接脱控件比较好理解先放一个SqlConnection组件,里面需要配置与数据库的连接然后再拖放一个SqlCommand控件,然后在这个控件的CommandText属性中键入查询语句:比如:insert into 表名 values ()最后再点它后面的“...”号,生成查询语句大概就这样!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行