将输入的texbox值分配给SQL查询| C#application | oracle [英] Assign entered texbox value to SQL query |C# application|oracle

查看:74
本文介绍了将输入的texbox值分配给SQL查询| C#application | oracle的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 assign entered texbox value to Sql query |C#|Oracle
 
 **How do i assign the Textbox value to my SQL Query C#**

[C# Application UI][1][1]: https://i.stack.imgur.com/8Pzl7.jpg



In the Above Image i typed Tablename = PERSONDETAILS this entered value in textBox1.Text should be passed to my SQL Query as a Paramter.So Hard coding the table name in the SQl query will be reduced

Actual code where i want it to be Included

    "select * from all_all_tables WHERE table_name='PERSONSDETAILS'";

**code :**

    string conString = "User Id=hr;Password=hr;Data Source=localhost:1522/orcl.168.0.5;";
    OracleConnection con = new OracleConnection();
    con.ConnectionString = conString;
    con.Open();
    
    OracleCommand cmd = con.CreateCommand();
    cmd.CommandText = "select * from all_all_tables WHERE table_name='PERSONSDETAILS'";
    OracleDataReader reader = cmd.ExecuteReader();
    while (reader.Read())
    {
        readtext.Text = reader.GetString(0);
    }
    con.Close();





我尝试过:



i试图添加textbox1.Text.toString()代替table_name



table_name = '+ textbox1.Text.toSTring()+'



但这不起作用如何将输入的文本框值作为参数传递给sql查询



What I have tried:

i have tried to add the textbox1.Text.toString() in place of table_name

table_name='"+textbox1.Text.toSTring()+"'

but this is not working how do i pass the entered textbox value as parameter to the sql query

推荐答案

如解决方案1中所述,使用 OracleParameter 是将值绑定到SQL语句的正确方法。



但是,请尝试使用 OracleParameter类(ODP.NET) [ ^ ]。这是因为不推荐使用Microsoft版本,请参阅 Oracle和ADO.NET | Microsoft Docs [ ^ ]。



绑定值后,您可能希望使用名称而不是参数来表示参数所以尝试设置 BindByName [ ^ ]到 true 并使用:parametername 语法,如果:1
As mentioned in solution 1, using OracleParameter is the correct way to bind the value into the SQL statement.

However, try using OracleParameter Class (ODP.NET)[^] instead. This is because the Microsoft version is deprecated, see Oracle and ADO.NET | Microsoft Docs[^].

What comes to binding the values, you might want to use names instead of ordinals for the parameters so try setting BindByName[^] to true and using :parametername syntax instead if :1.


请参见此处: OracleCommand.Parameters Property(System.Data.OracleClient)| Microsoft Docs [ ^ ]


这篇关于将输入的texbox值分配给SQL查询| C#application | oracle的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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