我在網上找到很多方法連接到MS SQL數據庫。我在web.config中使用連接字符串。它的工作完全正常,我們想要什麼,看起來像這樣:ASP數據庫連接問題
<connectionStrings>
<add name="xxx"
connectionString="SERVER=xxx;UID=xxx;Trusted_Connection=Yes;DATABASE=xxx;"
providerName="xxx" />
</connectionStrings>
這是最好的方式來連接。我然後用一個asp web表單應用程序大多采用的GridView
<asp:SqlDataSource ID="MatchDataSource" Runat="server"
SelectCommand="SELECT * FROM [xxx].[Matcxxxh]"
UpdateCommand="UPDATE [xxx].[Matxxxch] SET [xxx] =
@xxx, [xxx] = @xxx, [xxx] =
@xxx WHERE [email protected] [email protected]"
ConnectionString="<%$ ConnectionStrings:xxx %>">
<UpdateParameters>
<asp:Parameter Type="String" Name="CSISN"/>
<asp:Parameter Type="String" Name="ProcName"/>
</UpdateParameters>
</asp:SqlDataSource>
<asp:GridView ID="GridView1" Runat="server"
DataSourceID="MatchDataSource" Width="100%">
<RowStyle BackColor="white" ForeColor="black" Font-Italic="false" BorderColor="Black" />
<Columns>
<asp:TemplateField SortExpression="xxx" HeaderText="xxx">
<EditItemTemplate>
<asp:TextBox ID="editxxx" Runat="server" Text='<%# Bind("xxx") %>'
MaxLength="15" ToolTip="Enter CSI SN"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" Runat="server" ErrorMessage="You must provide a xxx." ControlToValidate="editxxx">*</asp:RequiredFieldValidator>
</EditItemTemplate>
<ItemTemplate><asp:Label Runat="server" Text='<%# Bind("CSISN") %>' ID="Label1"></asp:Label></ItemTemplate>
</asp:TemplateField>
我的問題,使用它的
- 我要對這個正確?
- 任何人都可以點我一個適當的教程,將顯示最佳實踐?
- 如何在腳本結束運行時關閉連接?