Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# SQL
i want to write a query to select data from db in condition i want to use textbox1.text how can i do this??
in favor of multy time using of this query i want to write witoth Qcommand.Parameters.AddWithValu command.
my code is:
string commandText = "select id from moshtari where mobile="+ textBox3.Text;
               
                Qcommand.CommandText = commandText;
                Qcommand.CommandType = CommandType.Text;
                object k = Qcommand.ExecuteScalar();
with this i see error.
Posted 8-Dec-12 22:23pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Qcommand.Parameters.AddWithValue("mobile",textbox3.Text);
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Write Like-
 
string commandText = "select id from moshtari where mobile=@mobileno;
Qcommand.Parameters.AddWithValue("@mobileno",Textbox3.Text);
  Permalink  
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 223
1 Sascha Lefévre 175
2 Abhinav S 170
3 Richard Deeming 155
4 CHill60 150
0 Sergey Alexandrovich Kryukov 7,156
1 OriginalGriff 6,410
2 Maciej Los 2,877
3 Abhinav S 2,732
4 Peter Leow 2,694


Advertise | Privacy | Mobile
Web01 | 2.8.150414.1 | Last Updated 9 Dec 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100