将输入的texbox值分配给Sql查询| C#| Oracle [英] assign entered texbox value to Sql query |C#|Oracle
问题描述
**如何将文本框值分配给我的SQL查询C#**
[C#应用程序用户界面]: https://i.stack.imgur.com/8Pzl7.jpg
在上图中我输入了Tablename = PERSONDETAILS这个在textBox1.Text中输入的值应该传递我的SQL查询作为Paramter.So在SQl查询中对表名进行硬编码将被减少
实际代码我希望它包含在内
  "select * from all_all_tables WHERE table_name ='PERSONSDETAILS'" ;;
$
**代码:**
  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);
  }¥b $ b   con.Close();
**How do i assign the Textbox value to my SQL Query C#**
[C# Application UI]: 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();
推荐答案
嗨raj bhai,
欢迎来到MSDN论坛。
我们已将您的反馈指示给相应的工程团队进行进一步评估。由于他们今天下班,团队
将审核反馈并通知您明天的下一步。请耐心等待,谢谢您的理解。
May
这篇关于将输入的texbox值分配给Sql查询| C#| Oracle的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!