小妹求助技术问题

来源:百度知道 编辑:UC知道 时间:2024/05/30 04:30:22
小妹最近学习c#,遇到要打印datagridview框的内容,想用水晶报表打印出来,哪位哥哥能帮帮忙嘛!(datagridview没有数据源)

参考答案:红素天生谁饰妆。桂楼椒阁木兰堂,绣户雕轩文杏梁。

先绑定数据库
SqlConnection thisConnection = new SqlConnection("Data Source=localhost;Integrated Security=SSPI;Initial Catalog=chaoshi");
SqlDataAdapter thisAdapter = new SqlDataAdapter();
DataSet thisDataSet = new DataSet();
SqlCommand thisCommand = new SqlCommand("select id as 编号,name as 名称,dizhi as 地址,yb as 邮编,cjdh as 厂家电话 ,lxr as 联系人,lxrdh as 联系人电话,yx as 邮箱,cz as 传真 from tgys", thisConnection);
thisAdapter.SelectCommand = thisCommand;
thisConnection.Open();
thisAdapter.Fill(thisDataSet, "tgys");
thisConnection.Close();
dataGridView1.DataSource = thisDataSet.Tables["tgys"];

我写的一个连接数据库并绑定的程序,数据库名chaoshi,表名tgys,列名id,name...等等.可以根据你自己的情况修改

打印就不知道了