user15213948
user15213948

Reputation: 13

Passing integer value from textbox in SQL select statement

I have an integer in a textbox(Integer retrieved from another form using TOstring) I want to use in an sql select statement.
For example, select * from table where column = textbox. The problem is, npgsql gives an error saying I'm trying to pass string into integer column. I try to cast(::int) but still got errors.

Any ideas!

Upvotes: 0

Views: 389

Answers (2)

Vivek Nuna
Vivek Nuna

Reputation: 1

You can do it like this.

string text = textbox.Text;
int id;
bool isConvertibleToInteger = int.TryParse(text, out id);

Please avoid select *, instead provide the column names

Upvotes: 1

user15213948
user15213948

Reputation: 13

I solved this issue. I called the SQL on tab click event and all worked fine. Datagridview properly filtered out the rows using textbox integer input. –

Upvotes: 0

Related Questions