如题。本人刚接触 希望大虾们能给个代码参考。
解决方案 »
- c#安装程序怎么做
- devepress gridcontrol 的问题
- 有谁做过门禁系统?
- IE下某个页面Cookie失效 但其它的可以照常登录 在线等
- 如何在C#字符串中包含双引号
- 分太多,散之!
- 再问正则表达式操作INI问题,高分!!!
- 怎样获取treelist中单元表格的内容
- 通讯问题,给出答案者最少送分50
- public void Page_Load(object sender, System.EventArgs e)为什么打开完成后没显示呢详情请看(UP也有分的啊)!!
- 求高手指点 给textbox赋值并保存以便程序下次启动能进入不同的设置
- page的StyleSheetTheme问题
using system.data.sqlclientdataset ds= new dataset();
string connectionString=连接字符串
string commandString=查询语句(如"select * from 表 where 内容='"+ textbox.text +"'")
SqlConnection con= new SqlConnection(connectionString)
con.open()
SqlDataAdapter da= new SqlDataAdapter(commandString)
da.fill(ds)
datagrid.datesource=ds.table[0].defaultview
如果别人输入textbox.text ="1 or 1=1";
就用"select * from 表 where 内容='"+ textbox.text +"'"查出所有东西了
//=================================================================================
private void button1_Click(object sender, EventArgs e)
{
string strConnection = "Provider=Microsoft.Jet.OleDb.4.0;";
strConnection += @"Data Source=D:\shop.mdb";
DataSet ds = new DataSet();
string commandString = " SELECT * FROM custom where name='" + textBox1.Text.ToString() + "' ";
SqlConnection conn = new SqlConnection(strConnection);
conn.Open();
SqlDataAdapter da = new SqlDataAdapter(commandString);
da.Fill(ds);
dataGridView1.DataSource = ds.Tables[0].DefaultView;
}
//=================================================================================运行的时候SqlDataAdapter da= new SqlDataAdapter(commandString)出现以下错误 请指教
1 与“System.Data.SqlClient.SqlDataAdapter.SqlDataAdapter(System.Data.SqlClient.SqlCommand)”最匹配的重载方法具有一些无效参数
2参数“1”: 无法从“string”转换为“System.Data.SqlClient.SqlCommand
还有 结尾时刻要记得加conn.close() 不然操作太多了连接池会饱和
不绑定是显示不出来结果的
我连的是ACCESS数据库 所以
using System.Data.SqlClient;
using System.Data.OleDb;namespace Shop
{
public partial class Form5 : Form
{
public Form5()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string strConnection = "Provider=Microsoft.Jet.OleDb.4.0;";
strConnection += @"Data Source=D:\shop.mdb";
DataSet ds = new DataSet();
string commandString = " SELECT * FROM custom where customer='" + textBox1.Text.ToString() + "' ";
OleDbConnection conn = new OleDbConnection(strConnection);
conn.Open();
OleDbDataAdapter da = new OleDbDataAdapter(commandString,strConnection);
da.Fill(ds);
dataGridView1.DataSource = ds.Tables[0].DefaultView;
conn.Close();
} }
}
using System.Data.SqlClient;// 连接数据库
SqlConnection connection = new SqlConnection();
connection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\MyData.mdb";// 创建命令
SqlCommand command = new SqlCommand();
command.Connection = connection;
command.CommandText = "select * from tableName where someField=" + "'" + textBox.Text + "'";// 打开连接
connection.Open();// 执行命令
DataSet dataSet = new DataSet();
SqlDataAdapter dataAdapter = new SqlDataAdapter(command);
dataAdapter.Fill(dataSet);// 将查询结果显示在DataGridView上
dataGridView.datesource = dataSet.Table[0];// 如果是Web程序,还需要进行绑定dataGridView.Bind();// 关闭连接
connection.Close();
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
private void button10_Click(object sender, EventArgs e)
{
//输入房屋情况进行查询
SqlConnection com = new SqlConnection("Data Source=PC-201202221639;Initial Catalog=XSGL;Integrated Security=True");
SqlDataAdapter qksda = new SqlDataAdapter("select * from cz where 房屋情况='" + comboBox3.Text + "'", com);
DataTable qkdt = new DataTable();
qksda.Fill(qkdt);
dataGridView1.DataSource = qkdt;
}
你可以查找这个写的,希望能帮到你的