本文介绍了如何使用C#从Texbox将数据插入dataBase中的两个单独列中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将数据插入到Texbox的dataBase中的两个单独的列中使用C#



i也希望将数据插入dataBase中的两个单独的列

这里我有2个多行文本框

如下





forBoxI1 for InSerailNo(InModel)

textBox2 for OutSerailNo(OutModel)



这里在textbox1中输入数据,如T0PQR,T0ABC

textbox2 i enter数据如T0123,T0783



当我点击插入按钮时,值应插入数据库表中,如下所示



DataBAse表

--------------



InSerial | OutSerail

----------------------

T0PQR | T0123

---------------------

T0ABC | T0783

----------------------

How to insert the data into two seperate columns in dataBase from Texbox usingg C#

i want too insert data into two seperate columns in dataBase
here i have 2 multiline Textboxs
namely as follows


textBox1 for InSerailNo(InModel)
textBox2 for OutSerailNo(OutModel)

here in textbox1 i enter data like T0PQR,T0ABC
textbox2 i enter data like T0123,T0783

when i click on Insert Button the values should be insert in database table as follows

DataBAse Table
--------------

InSerial | OutSerail
----------------------
T0PQR | T0123
---------------------
T0ABC | T0783
----------------------

推荐答案

                string[] insert__Value1= Regex.Split(textBox1.Text , ",");
    string[] insert__Value2= Regex.Split(textBox2.Text , ",");

for(int i=o;i<insert__value1.length;i++)>
{
insert into your tablename (value1,value2) values('"+ insert__Value1[i] + "','"+insert__Value2[i]+"'");
}


protected void btnSubmit_Click(Object Sender, EventArgs e)
{
SqlConnection con=new SqlConnection(connectionStringParameter)
con.Open();
string query="insert into table_name(InSerial,OutSerail)values
('"+textbox1.Text+"','"+textbox2.Text+"')";
SqlCommand cmd=new SqlCommand(query,con);
cmd.ExecuteNonQuery();
con.Close();
}


这篇关于如何使用C#从Texbox将数据插入dataBase中的两个单独列中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 14:28