根据用户输入从数据库中检索数据(单选按钮) [英] Retrieve A data from database based on user input(radio button)

查看:71
本文介绍了根据用户输入从数据库中检索数据(单选按钮)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以帮助我根据用户输入从数据库中检索数据的代码吗.例如:用户输入(单选按钮,下拉列表框).紧急我需要.help我

Can any one help me out in the code for retrieve a data from database based on user input .Example :user giving input in(radio button ,dropdownlist box).Urgently i need .help me

推荐答案

1.在Web配置中配置连接字符串.
< configuration>
< connectionstrings>
< add name ="MyDbConn">
connectionString ="Server = MyServer;数据库= pubs;用户ID = MyUser;密码= P @ ssw0rd"
providerName ="System.Data.SqlClient"/>




2.然后使用以下代码..

SqlConnection ObjSqlConnection =新的SqlConncetion();
ObjConnection.ConnectionString = ConfigurationManager.ConnectionString ["MyDbConn"].tostring();
ObjSqlConnection.open();
SqlCommand ObjSqlCommand =新的SqlCommand(存储过程的名称",ObjSqlConnection);
ObjSqlCommand.Parameters.Add(存储过程中的输入名称",DropDownList.SelectedItem.ToString());
ObjCommand.CommandType = CommandType.StoredProcedure;
ObjCommand.ExecuteReader();
while(Reader.Read())
{
//通过索引从存储过程结果中获取u所需的值;
}
ObjSqlConnection.close();


我希望你能理解....
1.Configure a Connection String in web config..

<configuration>
<connectionstrings>
<add name="MyDbConn">
connectionString="Server=MyServer; Database=pubs; User Id=MyUser; password= P@ssw0rd"
providerName="System.Data.SqlClient" />




2.Then use the following code..

SqlConnection ObjSqlConnection=new SqlConncetion();
ObjConnection.ConnectionString=ConfigurationManager.ConnectionString["MyDbConn"].tostring();
ObjSqlConnection.open();
SqlCommand ObjSqlCommand=new SqlCommand("Name of the stored Procedure",ObjSqlConnection);
ObjSqlCommand.Parameters.Add("Input Name in stored Procedure",DropDownList.SelectedItem.ToString());
ObjCommand.CommandType=CommandType.StoredProcedure;
ObjCommand.ExecuteReader();
while(Reader.Read())
{
//Get What value u needed from the stored procedure result through the index;
}
ObjSqlConnection.close();


I hope u understood....


这篇关于根据用户输入从数据库中检索数据(单选按钮)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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