Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9213717
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:48:50+00:00 2026-06-18T01:48:50+00:00

I have created a button to add the fields in a a textbox and

  • 0

I have created a button to add the fields in a a textbox and I wanted to pass the textbox name as parameter in a sub,which inturn inserts into the database..How can i do it..pls find my code for reference below in vb.net

The code for inserting the values in database

Sub Add_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click

        Dim addedButton As Button = sender
        Dim sqlcmd As SqlCommand
        Dim insertdata As String

        addedButton.Text = "Added"
        adduser = True
        addedButton.Enabled = True

        If (cname.Value = " " Or cid.Value = " " Or cadd.Value = " " Or cph.Value = " " Or fax.Value = " " Or cmail.Value = " ") Then
            Message.InnerHtml = "ERROR: Null values not allowed for " _
                & "Client ID, Name"
            Message.Style("color") = "red"
            BindGrid()
        Else
            Message.InnerHtml = "<b>Client Record has been added</b><br/>"     
        End If

        insertdata = "INSERT INTO dbo.ClientInfo([Client Name],[Client ID],[Client Address],[Client Telephone No],[Client Fax No],[Client E-mail]) values("
        insertdata = insertdata + " ' " + cname.Value + " '," + cid.Value + ",' " + cadd.Value + " '," + cph.Value + "," + fax.Value + "," + cmail.Value
        sqlcmd = New SqlCommand(insertdata, sqlcon)



        Try
            sqlcmd.Connection.Open()
            Dim addcount As Integer = sqlcmd.ExecuteNonQuery()

            If addcount > 0 Then
                Message.InnerHtml = "Record successfully Added"
            Else
                Message.InnerHtml = "Record not added"
            End If

        Catch ex As SqlException

            If ex.Number = 2627 Then
                Message.InnerHtml = "ERROR: A record already exists with " _
                   & "the same primary key"
            End If
        Finally
            sqlcmd.Connection.Close()
            BindGrid()
        End Try      
    End Sub


    <asp:Button id="Button1"
                   Text="Add data"
                   OnClick="Add_Click"
                   runat="server"/><br />

  Name:<input type ="text" id="cname" name="" value="" runat="server"/><br />
              ID: <input type = "text" id="cid" name="txtclientid" value="" runat="server"/><br />
              Address:<input type="text" id="cadd" name="txtclientadd" value="" runat="server"/><br />
              Phone No:<input type="text" id="cph" name="txtno" value="" runat="server" /><br />
              Fax No:<input type="text" id="fax" name="faxno" value="" runat="server"/><br />
              E-mail:<input type="text" id="cmail" name="mail" value="" runat="server"/><br />
              <input type="reset" name="reset" value="Clear" /><br />
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T01:48:52+00:00Added an answer on June 18, 2026 at 1:48 am

    Not exactly what you asked for, but closer to what you should be doing:

    Public Sub InsertClientInfo(ByVal ClientName As String, ByVal ClientID As Integer, ByVal ClientAddress As String, ByVal ClientPhone As String, ByVal ClientFax As String, ByVal ClientEmail As String)
    
        Dim sql As String = _
          "INSERT INTO ClientInfo (" & _
              "[Client Name],[Client ID],[Client Address],[Client Telephone No],[Client Fax No],[Client E-mail]" & _
         ") VALUES (" & _
              "@ClientName,  @ClientID,  @ClientAddress,   @ClientPhone,         @ClientFax,     @ClientEmail)"
    
        Using cn As New SqlConnection("connection string"), _
              cmd As New SqlCommand(sql, cn)
    
            'I had to guess at the column types and lengths here. Adjust accordingly
            cmd.Parameters.Add("@ClientName", SqlDbType.NVarChar, 50).Value = ClientName
            cmd.Parameters.Add("@ClientID", SqlDbType.Int).Value = ClientID
            cmd.Parameters.Add("@ClientAddress", SqlDbType.NVarChar, 200).Value = ClientAddress
            cmd.Parameters.Add("@ClientPhone", SqlDbType.NVarChar, 16).Value = ClientPhone
            cmd.Parameters.Add("@ClientFax", SqlDbType.NVarChar, 16).Value = ClientFax
            cmd.Parameters.Add("@ClientEmail", SqlDbType.NVarChar, 50).Value = ClientEmail
    
            cn.Open()
            cmd.ExecuteNonQuery()
        End Using
    End Sub
    

    Note that I had to guess at data types and sizes. You need to fix that to make your actual table definitions. Call it like this:

    InsertClientInfo(textname.Text, Convert.ToInt32(textclientid.Text), txtclientadd.Text, txtno.Text, faxno.Text, mail.Text)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a button which I want to expand/contract. I found a way
I have a system that when a button is pressed a textbox is created
I have created button 2 below: <input id=Button1 type=button value=Stop onclick=alert('hello world');/> <input id=Button2
I have created a button CSS class that uses background images with different positions
I have created a button in my Android application & I tried to set
I have created a button. So when I click the button it gives me
I have a Main class and a HelloWorld class. I have created a button
I am new to iphone development. I have created a button in the view.
I have created one dynamic button in my application and I call the following
I have created my own button class called custom_btn. I created it on the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.