嵌入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(
id,
name,
primary key (id)
);
studentInfo(
id,
age,
address,
foreign key(id) references outTable(id) on delete cascade on update cascade
);
当我们删除student表的时候自然希望studentInfo里的相关信息也被删除,这就是外键起作用 ......
select a.ClassName,a.CourseName,sum(不及格) as 不及格,sum(差) as 差,sum(中等) as 中等,sum(好) as 好 ,sum(不及格)+sum(差)+sum(中等)+sum(好) as 班级总人数 from (select StudentID,ClassName,CourseName,1 as 不及格,0 as 差,0 as 中等,0 as 好 from StudentScore where ScoreRemark='fail' union all
select Stu ......
功能:小写金额转换成大写
参数:@LowerMoney 小写金额 加上小数点最长可以保留38位
输出:大写金额
简介:SQL版 小写金额转换成大写金额(最多可以精确到小数点四位)
注: Decimal 数据类型最多可存储 38 个数字
转载:请保留以上信息,谢谢!!!
********************************* ......
Magento是在Zend Framework的基础上搭建而来,有两种方式可以从Magento的collection获得真正的SQL语句。
以 Mage::getResourceModel('reports/product_collection') 为例:
1
$collection=Mage::getResourceModel('reports/product_collection');
......