典型代码-linq 基本的增加记录操作
来源:互联网 发布:html可以连接数据库吗 编辑:程序博客网 时间:2024/06/16 08:59
添加项目
添加窗体
窗体添加dataGridView1
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
DataClasses1DataContext da = new DataClasses1DataContext();
t001 cus = new t001();
cus.bukrs = "8002";
cus.text = "文华传媒有限公司";
cus.addr = "河西路大浦街33号五里";
//这两句话有点像以前学过的事务,只有在添加完成之后才会写入数据库
da.t001.InsertOnSubmit(cus);
da.SubmitChanges();
var query = from s in da.t001
where s.bukrs != "2222"
select s;
dataGridView1.DataSource = query;
}
}
}
app.config的代码
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
</configSections>
<connectionStrings>
<add name="WindowsFormsApplication1.Properties.Settings.sapConnectionString"
connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=C:\DataBase\sap.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>
再建立一个空网站
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string str = "Data Source=.\\SQLEXPRESS;AttachDbFilename=C:\\DataBase\\sap.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True";
SqlConnection myConnection = new SqlConnection(str);
myConnection.Open();
SqlCommand myCommand = new SqlCommand("select * from t001", myConnection);
SqlDataAdapter Adapter = new SqlDataAdapter();
Adapter.SelectCommand = myCommand;
DataSet myDs = new DataSet();
Adapter.Fill(myDs);
Response.Write("<h3>用使用DataSet显示CustomerInfo数据表内容</h3>");
Response.Write("<table border=1 cellspacing=0 cellpadding=2>");
DataTable myTable = myDs.Tables[0];
Response.Write("<tr bgcolor=yellow>");
foreach (DataColumn myColumn in myTable.Columns)
{
Response.Write("<td>" + myColumn.ColumnName + "</td>");
}
Response.Write("</tr>");
foreach (DataRow myRow in myTable.Rows)
{
Response.Write("<tr>");
foreach (DataColumn myColumn in myTable.Columns)
{
Response.Write("<td>" + myRow[myColumn] + "</td>");
}
Response.Write("</tr>");
}
Response.Write("</table>");
myConnection.Close();
}
}
- 典型代码-linq 基本的增加记录操作
- Linq的基本操作
- LINQ傻瓜教学之一:新增dbml文件和基本的增加删除和修改记录
- LINQ XML的基本操作
- LINQ XML的基本操作
- LINQ XML的基本操作
- Linq的基本用法,代码
- c# linq to sql 的基本操作
- 增加的 LINQ 表达式
- Linq 基本查询操作
- linq基本操作
- ecshop增加积分记录的相关代码
- ADO的基本操作(二)增加
- 单链表的基本操作(初始化,增加,删除)
- Linq 的基本操作 之Union All/Union/Intersect 操作
- Linq 的基本操作 之Union All/Union/Intersect 操作
- 【记录】VIM的基本操作
- 代码_ADO_增加记录
- opencv或者libvlc库这种遇到窗口句柄想要放到MFC中的处理代码如下:
- 剪发 Haircut
- 新的开始——1月英语
- maven 安装之后 settings.xml的配置详解
- kafka集群安装
- 典型代码-linq 基本的增加记录操作
- Javaweb学习之jsp与servelet的区别
- Socket简单使用
- # git团队开发流程小结
- 行人再识别(行人重识别)【包含与行人检测的对比】
- ios 修改应用名称
- 四川麻将地胡
- Android 消息处理机制
- 九度oj 二叉排序树 1201,1009 c++