嵌入SQL语句
嵌入SQL语言:
我将一个sql链接到数据库,该数据库名为master(系统数据库)
then 给数据库添加新表,建立三个key:userid(int),name(char(10)),password(char(10))
在窗体中弄三个textbox控件,分别定义Name属性为userid,name,password;
再来一个button
以下是Form1.cs中的代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Data.OleDb;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Runtime.InteropServices;
using System.Configuration;
namespace Str
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void submit_Click(object sender, EventArgs e)
{
/*
* connect to Sql Server
* 方法一:写在这里
*/
//string strConnection = "Data Source=ZRQ-PC;";
//strConnection += "Initial Catalog=master;Integrated Security=True";
// SqlConnection objConnection = new SqlConnection(strConnection);
/*
* 方法二:
* 这个方法为工程添加了新建项“应用程序配置文件”
* 将上面的那段写在App.config里
*/
string strConnection = ConfigurationSettings.AppSettings["connectionstring"];
SqlConnection objConnection = new SqlConnection(strConnection);
/************************************************************************/
if (name.Text == "")
MessageBox.Show("请输入姓名!", "提示", 0);
else
{
objConnection.Open();
SqlCommand cmd = new SqlCommand("select * from judging where userid='" + userid.Text.Trim() + "'", objConnection);
/*
***********************************************************************************************
相关文档:
操作数据库结构的常用Sql
下面是Sql Server 和 Access 操作数据库结构的常用Sql,内容由海娃整理,不正确与不完整之处还请提出,谢谢。
新建表:
create table [表名]
(
[自动编号字段] int IDENTITY (1,1) PRIMARY KEY ,
[字段1] nVarChar(50) default '默认值' null ,
[字段2] ntext null ,
[字段3] dateti ......
Student(S#,Sname,Sage,Ssex) 学生表
Course(C#,Cname,T#) 课程表
SC(S#,C#,score) 成绩表
Teacher(T#,Tname) 教师表
问题:
1、查询“001”课程比“002”课程成绩高的所有学生的学号;
select a.S# from (select s#,score from SC where C#='001') a,(select s#,score
fr ......
-- ======================================================
--列出SQL SERVER 所有表,字段名,主键,类型,长度,小数位数等信息
--在查询分析器里运行即可,可以生成一个表,导出到EXCEL中
-- ======================================================
SELECT
(case when a. ......
在这一步中,需要指定游标的属性和根据要求产生的结果集。有两种方法可以指定一个游标。
形式1(ANSI 92)
DECLARE cursor_name [INSENSITIVE] [SCROLL] CURSOR
FOR select_statement
[FOR {READ ONLY | UPDATE ][OF column_list]}]
形式2
DECLARE cursor_name CURSOR
[LOCAL | GLOBAL]
[FORWARD ......
用T-SQL做数据库分页查询也有好几年了,但对于各种查询方法的写法一至都没怎么去理会,最近参与了几个项目的开发,几个项目中分页查询的写法也不相同,这也让我产生了确认几种写法效率问题的兴趣。(注:我所说的几种写法都是需要返回总记录数的分页)
1、生成测试数据
select a.* into test from sys.columns a,sys.colu ......