テキストボックスにフィールドを追加するボタンを作成し、サブのパラメータとしてテキストボックス名を渡したいと思いました。これにより、データベースに挿入されます。どうすればよいですか。plsは、以下のvbで参照するコードを見つけます。 。ネット
データベースに値を挿入するためのコード
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 />