我是SqlServer的新手,现在我已SqlLocalDb安装在本地工作.很好,但我通常可以看到两个连接字符串,两者都有效:
Data Source=(localdb)\v11.0;Integrated Security=true;
Run Code Online (Sandbox Code Playgroud)
和
Server=(localdb)\v11.0;Integrated Security=true;
Run Code Online (Sandbox Code Playgroud)
这两者之间究竟有什么区别?
在我的页面上,我有一个DropDownList用数据库值填充的SqlDataSource(参见下面的代码).
如何在值之前添加自己的文本或空行?
<asp:DropDownList ID="drpClient" runat="server" Width="200px"
AutoPostBack="True" DataSourceID="dsClients" DataTextField="name"
DataValueField="client_id">
</asp:DropDownList>
<asp:SqlDataSource ID="dsClients" runat="server"
ConnectionString="my_connection_string"
ProviderName="System.Data.SqlClient"
SelectCommand="SELECT [client_id], [name] FROM [clients]">
</asp:SqlDataSource>
Run Code Online (Sandbox Code Playgroud)
谢谢.
PS你建议使用SqlDataSource或者更好地填充另一种方式吗?
我想将变量从后面的代码传递给SqlDataSource的SelectCommand?
我不想使用内置参数类型(如ControlParemeter,QueryStringParameter等)
我需要通过一个可变的?
以下示例不起作用
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:itematConnectionString %>" SelectCommand = "SELECT items.name, items.id FROM items INNER JOIN users_items ON items.id = users_items.id WHERE (users_items.user_id = @userId) ORDER BY users_items.date DESC" >
<SelectParameters>
<asp:Parameter DefaultValue="<%= userId %>" Name="userId" DbType="Guid" />
</SelectParameters>
</asp:SqlDataSource>
Run Code Online (Sandbox Code Playgroud) 如果网页需要一些数据,为什么不只是让SQLDataSource调用存储过程?为什么使用ObjectDataSource来调用然后调用存储过程的业务对象?我知道在.net框架上构建的其他应用程序(比如桌面应用程序)可以访问业务对象,但是如果应用程序永远只是一个Web应用程序呢?
更清楚:
什么时候应该使用SqlDataSource或ObjectDataSource?
如何激励选择?
我需要在网格视图中显示数据,并为某些列合并行.请帮我准备以下定义格式的网格视图:

原始数据来自数据库格式如下:

请帮助我找到动态有效地完成此任务的最佳方法.
我需要在启用了缓存的情况下手动清除SqlDataSource上的缓存.我已经尝试设置EnableChaching = false,并且CacheDuration = 0(以及= 1)并且似乎都没有使缓存中已有的内容到期 - 尽管它们似乎确实阻止了新的SELECT被缓存.
如何手动使该缓存失效?
谢谢.
每当我从部署在JBoss 5.1上的应用程序连接到HSQLDB时,它都会抛出异常:Caused by: org.jboss.resource.JBossResourceException: Could not create connection; - nested throwable: (java.sql.SQLException: error in script file line: 1 Unexpected token UNIQUE, requires COLLATION in statement [SET DATABASE UNIQUE]).
我的HSQLDB脚本文件读取如下内容:`SET DATABASE UNIQUE NAME HSQLDB2E0BAD63B3
SET DATABASE GC 0
设置数据库默认结果存储器行0
设置数据库事件日志级别0
.....`
有没有人知道这个异常意味着什么,或者我应该在HSQLDB配置中改变一些东西?
此致,萨蒂亚
对于SqlDataSource,我可以为传入参数配置外部源.例如,它可能是QueryString,Session,Profile等.但是我没有选择使用User作为源.
我知道我可以在插入,选择,更新,删除事件中为参数提供值.但我认为这不是一个优雅的解决方案,因为我已经在aspx文件中定义了一些参数.我不希望在两个单独的地方定义参数.它弄得一团糟.
那么我可以在.aspx文件中以某种方式定义此参数吗?
<SelectParameters>
<asp:QueryStringParameter DefaultValue="-1" Name="ID"
QueryStringField="ID" />
//User.Identity.Name goes here as a value for another parameter
</SelectParameters>
Run Code Online (Sandbox Code Playgroud) ddl2成功填充基于ddl1选定值.
我的问题是在添加新数据之前,ddl2中已经存在的数据不会被清除,因此ddl2内容在每次更改ddl1时都会继续增长.
<asp:DropDownList ID="ddl1" RunAt="Server" DataSourceID="sql1" DataValueField="ID1" DataTextField="Name2" AppendDataBoundItems="True" AutoPostBack="True">
<asp:ListItem Text="ALL" Selected="True" Value="0"/>
</asp:DropDownList>
<asp:DropDownList ID="ddl2" RunAt="Server" DataSourceID="sql2" DataValueField="ID2" DataTextField="Name2" AppendDataBoundItems="True" AutoPostBack="True">
<asp:ListItem Text="ALL" Selected="True" Value="0"/>
</asp:DropDownList>
<asp:SqlDataSource ID="sql1" RunAt="Server" SelectCommand="sp1" SelectCommandType="StoredProcedure"/>
<asp:SqlDataSource ID="sql2" RunAt="Server" SelectCommand="sp2" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:ControlParameter Type="Int32" Name="ID1" ControlID="ddl1" PropertyName="SelectedValue"/>
</SelectParameters>
</asp:SqlDataSource>
Run Code Online (Sandbox Code Playgroud)
我已尝试在选定的索引更改后面的代码中重新数据绑定以及items.clear但收效甚微.
Protected Sub ddl1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
ddl2.Items.Clear()
ddl2.DataSource = sql2
ddl2.DataBind()
End Sub
Run Code Online (Sandbox Code Playgroud)
题
如果下拉列表内容依赖于另一个下拉列表选定值,如何在填充新值之前清除asp:dropdownlist中的项目以进行清除?
请在VB中发布任何代码
我想设定的值sqldatasource的selectcommand参数@ClientID,如下面的代码,但它不工作了.
Dim strCommand = "SELECT caller_id, phone, name, email FROM callers WHERE client_id=@ClientID"
SqlDataSource2.SelectCommand = strCommand
SqlDataSource2.SelectParameters.Add("@ClientID", iClientID)
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
sqldatasource ×10
asp.net ×7
.net ×3
c# ×3
caching ×1
data-binding ×1
dropdownbox ×1
gridview ×1
hsqldb ×1
html-select ×1
jboss5.x ×1
localdb ×1
parameters ×1
sql-server ×1
variables ×1
vb.net ×1