- 10
- 0
- 约2.11万字
- 约 16页
- 2015-10-16 发布于江苏
- 举报
C#操作sql server数据库实例源代码.doc
C#操作sql server数据库实例源代码
1.实现的界面
2.要导出的命名空间
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;
using System.Configuration;
3.app.config配置
?xml version=1.0 encoding=utf-8 ?
configuration
configSections
/configSections
connectionStrings
add name=MingXinERP.Properties.Settings.mingxindataConnectionString1
connectionString=Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\App_Data\mingxindata.mdf;Integrated Security=True;User Instance=True
providerName=System.Data.SqlClient /
/connectionStrings
/configuration
4.窗口load事件的实现
此功能和刷新按钮的功能是一样的.
private void frmclientinfo_Load(object sender, EventArgs e)
{
try
{
string sql;
string strcon = ConfigurationManager.ConnectionStrings[MingXinERP.Properties.Settings.mingxindataConnectionString1].ToString();
SqlConnection con = new SqlConnection(strcon);
con.Open();
sql = select top 12 * from (select top 12 * from 客户信息 order by 编号 desc) a order by 编号 asc;//显示最后的12条记录
SqlDataAdapter da = new SqlDataAdapter(sql, con);
DataSet ds = new DataSet();
da.Fill(ds, abc);
dataGridView1.DataSource = ds.Tables[abc].DefaultView;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
5. dataGridView_CellClick的实现
是单击dataGridView单元格所触发的事件.
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
txtid.Text = Convert.ToString(dataGridView1[0, dataGridView1.CurrentCell.RowIndex].Value);
txtname.Text = Convert.ToString(dataGridView1[1, dataGridView1.CurrentCell.RowIndex].Value);
cbotype.Text = Convert.ToString(dataGridView1[2, dataGridView1.CurrentCell.RowIndex].Value);
cbofrom
您可能关注的文档
- 2015年教师招聘考试小学《教育心理学》章节练习:问题解决与创造性.doc
- 2015执业药师考试基础辅导.doc
- 2015检验技士练习题.doc
- 2015江西教师招聘《教育心理学》章节历年真题:学习动机.doc
- 2015江西教师招聘小学《教育心理学》章节练习:学习动机.doc
- 2015表面工程复习题.docx
- 2015高考化学二轮复习 专题8 电化学 - 含答案.doc
- 2015黄委会面试备考指导:面试中的语言能力基本要素.doc
- 2321DNA的分子结构.doc
- 80139_140504王陆雅思听力.ppt
- (2026春新版)部编版八年级语文下册《第一单元》PPT课件.pptx
- 2018电力监控系统网络安全监测装置技术规范.docx
- 2022电力监控系统安全防护方案审核要点.docx
- 2014电力电缆光伏系统EN 50618欧标.docx
- (2026春新版)人教版二年级数学下册《第三单元 万以内数的认识》教案.docx
- (2026春新版)人教版二年级数学下册《第四单元 万以内的加法和减法》教案.docx
- (2026春新版)人教版二年级数学下册《综合与实践 时间在哪里》教案.docx
- (2026春新版)苏教版二年级数学下册《综合与实践 时间有多长》教案 .pdf
- (2026春新版)部编版三年级语文下册第3单元(教案).docx
- (2026春新版)部编版三年级语文下册第8单元(教案).docx
原创力文档

文档评论(0)