开发者

Parse numbers in singe textbox for query

开发者 https://www.devze.com 2022-12-26 19:31 出处:网络
I’ve built a webform in Visual Web Developer Express 2008 to help me with my work.I use a webform to run query requests that are emailed to me.The inputs are in this format

I’ve built a webform in Visual Web Developer Express 2008 to help me with my work. I use a webform to run query requests that are emailed to me. The inputs are in this format

12312 12312

12312 12312

12312 12312

12312 12312

I enter the first number in a textbox and the second number in another textbox and click a button that runs a query and returns the results in a gridview(single row).

string strConn, strSQL;
            strConn = AppConfig.Connection
strSQL = 'select fields from table where FirstNum=:FirstNum and      SecondNum=:SecondNum';

            using (OracleConnection cn = new OracleConnection(strConn))
            {
                OracleCommand cmd = new OracleCommand(strSQL, cn);
                cmd.Parameters.AddWithValue(":FirstNum", txtFirstNum.Text);
                cmd.Parameters.AddWithValue(":SecondNum",
txtSecondNum.Text);
                cn.Open();

                using (OracleDataReader rdr = cmd.ExecuteReader())
                {
                    dgResults.DataSource = rdr;
                    dgResults.DataBind();
                }
                cn.Close();
            }

I had an idea to help me speed up my work. I’d like to be able to past both numbers in a single textbox

( like this 12312 12312 )

and have the code parse out the nubmers for the query. Or even better would be to past all of them in a multiline textbox like this

12312 12312

12312 12312

12312 12312

12312 12312

And have them all parsed and the query run for each line and the results all output to开发者_运维技巧 one gridview. I’m just not sure how to approach this. Any suggestions would be appreciated.

Thank you.


Perhaps something like:

string[] lines = textBox.Text.Split( '\n' );
foreach( var line in lines )
{
    var values = line.Split( ' ' );
    var num1 = int.Parse( values[0] );
    var num2 = int.Parse( values[1] );
    // do what you need to with num1, num2
}

You're going to want to add more error handling logic and resiliency to the code above - especially if the input comes from a human being.

0

精彩评论

暂无评论...
验证码 换一张
取 消