1) 对于带有复选框的网格视图,vb.net 中没有主键的表的更新查询的语法是什么?
免责声明:令人沮丧的是,添加主键不是一种选择。我的程序是一个大得多的系统中的一个小程序,数据管理很差。我的开发时间不包括重写其他软件。
以下是表的列,其中 AgentLeads 是数据库,MktDtaLeads_Scrubbed 是表:
FROM [AgentLeads].[dbo].[MktDtaLeads_Scrubbed] - [Last Name] ,[First Name],
[Middle Name] ,[Suffix] ,[Address Line 1] ,[Address Line 2] ,[City] ,[ST],
[ZipCode] ,[Email Address] ,[Phone Nbr] ,[Toll Free Nbr] ,[InsertDate] ,
[SentDate] ,[DoNotMail]
我现在拥有的代码不会显示任何错误,但当您选中复选框时不会更新 DoNotMail 字段,即使它确实显示文本“数据库中的 DoNotMail 值已更改为所选字段”。
对于我添加的 default.aspx.vb 后面的代码:
Public Sub gridview1_RowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs)
If e.CommandName = "UpdateDoNotMail" Then
With Me.SqlDataSource1
Dim box As CheckBox = DirectCast(sender, CheckBox)
If box.Checked = True Then
donotmail.SelectedValue = 1
.ConnectionString = ConfigurationManager.AppSettings("AgentLeadsConnectionString").ToString
.UpdateCommand = "UPDATE MktDataLeads_scrubbed set donotmail=@donotmail
WHERE [last name]=@lastname.selectedrow AND [first name]=@firstname.selectedrow AND [Address Line 1]=@Address Line 1.selectedrow"
Else
donotmail.SelectedValue = 0
.ConnectionString = ConfigurationManager.AppSettings("AgentLeadsConnectionString").ToString
.UpdateCommand = "UPDATE MktDataLeads_scrubbed set donotmail=@donotmail
WHERE [last name]=@lastname.selectedrow AND [first name]=@firstname.selectedrow AND [Address Line 1]=@Address Line 1.selectedrow"
End If
End With
End If
End Sub
这是 default.aspx 上 GridView 的代码:
<asp:GridView ID="GridView2" runat="server" CellPadding="2"
DataSourceID="SqlDataSource1" ForeColor="#333333" GridLines="None"
AutoGenerateColumns="False">
<Columns>
<asp:BoundField DataField="Last Name" HeaderText="Last Name"
SortExpression="Last Name" />
<asp:BoundField DataField="First Name" HeaderText="First Name"
SortExpression="First Name" />
<asp:BoundField DataField="Address Line 1" HeaderText="Addr 1"
SortExpression="Address Line 1" />
<asp:BoundField DataField="Address Line 2" HeaderText="Addr 2"
SortExpression="Address Line 2" />
<asp:BoundField DataField="City" HeaderText="City" SortExpression="City" />
<asp:BoundField DataField="ST" HeaderText="ST" SortExpression="ST" />
<asp:BoundField DataField="ZipCode" HeaderText="ZipCode"
SortExpression="ZipCode" />
<asp:BoundField DataField="Email Address" HeaderText="Email Addr"
SortExpression="Email Address" />
<asp:BoundField DataField="Phone Nbr" HeaderText="Phone Nbr"
SortExpression="Phone Nbr" />
<asp:TemplateField HeaderText="DoNotMail" SortExpression="DoNotMail">
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="true" CommandName="UpdateDoNotMail" Checked='<%# Bind("DoNotMail") %>'
Enabled="true" />
</ItemTemplate>
<EditItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="true" CommandName="UpdateDoNotMail" Checked='<%# Bind("DoNotMail") %>' />
</EditItemTemplate>
</asp:TemplateField>
</Columns>
2)当用户点击一个按钮时,是否可以在整个gridview上进行双向同步,这样您就不必在每次更改行时都进行更新?因为用户可能会选中该框,然后选中另一个框,然后取消选中一个框,这将是很多更新...