0

hey everyone i am using a select query and showing input string is not in correct format ...plz help me......
here is my query.....

int id = Convert.ToInt32(String.Format(@"SELECT Id FROM Student WHERE RegNo ='{0}' ", cmbRegNo.Text));

3
Contributors
7
Replies
8
Views
7 Years
Discussion Span
Last Post by Manak
Featured Replies
0

Sure!!
What you trying to do is to convert "SELECT Id FROM Student WHERE RegNo ='value' to Integral value!!
Just tel me what you need to do.
I expect you need to execute this query and take the result in the ID
So

string selectStatement = String.Format("SELECT Id FROM Student WHERE RegNo ='{0}' ", cmbRegNo.Text);
SqlCommand cmd = new SqlCommand(selectStatement, connection);
int id = (int)cmd.ExecuteScalar();
0

Sure!!
What you trying to do is to convert "SELECT Id FROM Student WHERE RegNo ='value' to Integral value!!
Just tel me what you need to do.
I expect you need to execute this query and take the result in the ID
So

string selectStatement = String.Format("SELECT Id FROM Student WHERE RegNo ='{0}' ", cmbRegNo.Text);
SqlCommand cmd = new SqlCommand(selectStatement, connection);
int id = (int)cmd.ExecuteScalar();

thanx 4 ur reply
i hv done dis nd its shoing the following error

String connectionString = System.Configuration.ConfigurationSettings.AppSettings["dsn"];

string Query = String.Format("SELECT RegNo FROM Student WHERE RegNo ='{0}' ", cmbRegNo.Text);

OleDbCommand cmd=new OleDbCommand(Query,connectionString);
int id =(int)cmd.ExecuteScalar();

Error 6 The best overloaded method match for 'System.Data.OleDb.OleDbCommand.OleDbCommand(string, System.Data.OleDb.OleDbConnection)' has some invalid arguments C:\Users\Manak\Desktop\smsfinal\StudentManagementSystem\StudentStatus.cs 166 34 StudentManagementSystem

0

Please use Code Tag :)

String connectionString = System.Configuration.ConfigurationSettings.AppSettings["dsn"];

string Query = String.Format("SELECT RegNo FROM Student WHERE RegNo ='{0}' ", cmbRegNo.Text);

OleDbCommand cmd=new OleDbCommand(Query,new OleDbConnection (connectionString));

int id =(int)cmd.ExecuteScalar();
0

Please use Code Tag :)

String connectionString = System.Configuration.ConfigurationSettings.AppSettings["dsn"];

string Query = String.Format("SELECT RegNo FROM Student WHERE RegNo ='{0}' ", cmbRegNo.Text);

OleDbCommand cmd=new OleDbCommand(Query,new OleDbConnection (connectionString));

int id =(int)cmd.ExecuteScalar();

now its showing to execute executescalar you need to open the connection and its closed

0

Little correction to Ramy's code.

String connectionString = System.Configuration.ConfigurationSettings.AppSettings["dsn"];

string Query = String.Format("SELECT RegNo FROM Student WHERE RegNo ='{0}' ", cmbRegNo.Text);

OleDbCommand cmd=new OleDbCommand(Query,new OleDbConnection (connectionString));
cmd.Connection.Open();
int id =(int)cmd.ExecuteScalar();
cm.Connection.Close();
0

u all rockkkkkkk
nd this site also rockss
thanku for helping me..

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.