从数据库中检索列数据 [英] Retrieving column data from database

查看:52
本文介绍了从数据库中检索列数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从我的表中检索一列数据,我想检查列数据是否包含我在文本框中输入的数据



string t =从产品中选择名称;

SqlDataAdapter fd = new SqlDataAdapter(t,DbConnection.mCon);

DataTable dtcc = new DataTable();

fd.Fill(dtcc);

// if(dtcc.Rows [0] [0] .ToString()== TextBox1.Text)

if (dtcc.Columns [0] .ToString()== TextBox1.Text)





i有一个名为product的表和一个名为的字段姓名



i有一个文本框,假设我在该文本框中输入一个名称,我想检查该名称是否在我的数据库中是否出现

i want to retrieve one column of data from my table and i want to check that column data is contain the data that i enter in my textbox

string t = "select Name from Product";
SqlDataAdapter fd = new SqlDataAdapter(t, DbConnection.mCon);
DataTable dtcc = new DataTable();
fd.Fill(dtcc);
//if (dtcc.Rows[0][0].ToString() == TextBox1.Text)
if(dtcc.Columns[0].ToString()==TextBox1.Text)


i have table named product and one field named in Name

i have one textbox suppose i enter a name in that textbox i want to check that name is
occure in my database or not

推荐答案

如果你尝试在查询中使用文本框的值,你可以做得更好。

例如

You would be able to do this better if you try using the value of the textbox in the query itself.
For e.g.
SqlCommand cmd = new SqlCommand("select name from Product where name like @City", conn);
SqlParameter param  = new SqlParameter();
param.ParameterName = "@Name";
param.Value         = textbox1.text;
cmd.Parameters.Add(param);
reader = cmd.ExecuteReader();



如果读者返回1或更多的计数,则已存在具有此名称的记录。


If the reader returns a count of 1 or more, a record with this name already exists.


这篇关于从数据库中检索列数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆