using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
string sqlData = "Data Source =.;Initial Catalog =Student11;uid=sa;pwd=3661849";
SqlConnection cmd = new SqlConnection(sqlData);
SqlCommand com = cmd.CreateCommand(); }
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
string sqlData = "Data Source =.;Initial Catalog =Student11;uid=sa;pwd=3661849";
SqlConnection cmd = new SqlConnection(sqlData);
SqlCommand com = cmd.CreateCommand(); }
}
}
System.Data.SqlClient.SqlCommand cmd = conn.CreateCommand(); //创建命令对象
cmd.CommandText = "select Name from [User] where ID=1"; //定义查询语句
conn.Open(); //打开数据库
Console.WriteLine(cmd.ExecuteScalar());
conn.Close(); //关闭连接
conn.Dispose(); //释放资源
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
string sqlData = "Data Source =.;Initial Catalog =Student11;uid=sa;pwd=3661849";
SqlConnection cmd = new SqlConnection(sqlData);
SqlCommand com = cmd.CreateCommand();
com.CommandText = "SELECT * FROM Student_1";//包括ID(int),name(vachar),picture(image)。
cmd.Open();
com.Connection = cmd;
Console.WriteLine (cmd.ExecuteScalar());
cmd.Close();
}
}
}//报错
我太无语了,你太新了!没看别人都不理你么5555555555555555你的问题得系统的教才行,我来不了了,我给你个建议,你去翻MSDN吧,没安装的话,上在线的http://msdn.microsoft.com/zh-cn/library/system.data.sqlclient.sqlcommand_methods.aspx
public SqlDB()
{
connectionString = System.Configuration.ConfigurationSettings.AppSettings["connectionString"];
}
public bool ExecutInsert(string StrCommand)
{
SqlConnection conn = new SqlConnection();
conn.ConnectionString = connectionString;
conn.Open(); SqlCommand comm = new SqlCommand();
comm.Connection = conn;
comm.CommandText = StrCommand;
if (comm.ExecuteNonQuery() > 0)
{
return true;
}
else
{
return false;
}
}
....<appSettings>
<add key="connectionString" value="Data source=WLF-006\SQLEXPRESS;Database=RockTest;Trusted_Connection=True;" />
</appSettings>这是在web。config
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;namespace 显示表中数据2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void Form1_Load(object sender, EventArgs e)
{
SqlConnection mysql = new SqlConnection();
mysql.ConnectionString = "Data Source=localhost;Initial Catalog=MyBookShop;Integrated Security=True";//数据库名
SqlCommand sqlCommand = new SqlCommand();
sqlCommand.Connection = mysql;
sqlCommand.CommandType = CommandType.Text;
sqlCommand.CommandText = "SELECT * FROM Category";//表名
mysql.Open();
SqlDataReader sqlDateRreader;
sqlDateRreader = sqlCommand.ExecuteReader();
while (sqlDateRreader.Read())
{
richTextBox1.Text += " " + sqlDateRreader["CategoryID"].ToString() + "\t"
+ sqlDateRreader["CategoryName"].ToString() + "\r";//表里面有两列---CategoryID和CategoryName }
Console.WriteLine(richTextBox1.Text);
mysql.Close();
sqlDateRreader.Close();
}
}
}