Insert into single column multiple textboxes from WinForm

Mathh

Member
Joined
May 16, 2013
Messages
7
Programming Experience
Beginner
Hi all,

Maybe You will find a solution - how to save (insert into statement) multiple textboxes in one column in SQL table?
Well, what I have is a winform with 20 textboxes (each is for one metric). Table is build like:

Team | GSDate | GSGroup | GSMetric | GSValue | LoggedBy

what I would like to achieve, using one buton event to save all my textboxes:

VB.NET:
Team   |   GSDate    |    GSGroup    |    GSMetric    |     GSValue    |    LoggedBy
  FR      08/21/2013          CRC               Calls             100%            User1
  FR      08/21/2013          CRC              Emails             98.7%         User1
  FR      08/21/2013          CRC             Handled             12               User1

it's a sample, but for GSMetric I would like to add all values from textboxes, and for GSValue as well, because those are changing in relation to remaining values (Team, GSDate, GSGroup, LoggedBy)

I'm using parameters.AddWithValue.

VB.NET:
        Sql = "INSERT INTO tbl_Metrics (Team, GSDate, GSGroup, GSMetric, GSValue, LoggedBy) VALUES (@Team, @date, @group, @metric, @value, @user)"        Using comm As New SqlCommand()
            With comm
                .Connection = cn
                .CommandType = CommandType.Text
                .CommandText = Sql
                .Parameters.AddWithValue("@Team", gslog.cbGSTeam.SelectedItem)
                .Parameters.AddWithValue("@date", MetDate.SelectedDate)
                .Parameters.AddWithValue("@group", me3.Text)
                .Parameters.AddWithValue("@metric", meH3.Text)
                .Parameters.AddWithValue("@value", m1.Text.ToString)

Thank you in advance!
 
You should add a row for each to a DataTable and then save the lot in one go. You can put the TextBoxes in an array and loop through that to create the rows. Check out my thread below that includes code examples for various ADO.NET scenarios, including this one.

Retrieving and Saving Data in Databases
 

Latest posts

Back
Top