<script type ="text/javascript">
$(document).ready(function(){
$("#Web1_hid").val($("#div").html());
// select add 1.
$("#sel").append("<option value='213123'>24324</option>");
//add 2.
var op = new Option();
op.text = "dsaf";
op.value = "asdf";
var sel= $("#sel")[0];
sel.options.add(op);
// 遍历
$("#sel option").each(function(){
alert($(this).val());
});
$("#sel").click(function(){
//获取值:
alert($("#sel option:selected").val());
// 取消选 中项:
$("#sel option:selected").removeAttr("selected");
});
});
</script>
<div id ="div">123455</div>
<select id ="sel" name ="sel"></select>
<input type ="hidden" id ="hid" value ="" runat ="server"/>
The following is an example showing an already populated select. Clicking the "Add option" button adds a new option to the end of the select and makes it the selected one. Clicking "Replace options" replaces them with a new set of options and then selects the "Green" one.
Note that the above example will not work if you are reading this in a feed reader. In this case click through to view this post in a web browser.
Adding a single option can be done by appending HTML to the select box. The select in the above example has an id of "example" i.e. <select id="example"> and using this method adding a new option by appending HTML can look like this:
1 |
$('#example').append('<option value="foo" selected="selected">Foo</option>'); |
This newly added option will be the selected option; to change this behavior remove the selected="selected" part.
To avoid having to write and append HTML and stick with a more Javascript approach the new option can be appended with jQuery by creating a new option object. This next example does not work correctly in Internet Explorer; it will add the new option but only the value and not display any text.
1 |
$('#example').append(new Option('Foo', 'foo', true, true)); |
The true, true part at the end will make this item the selected one.
This method gets a handle to the options and adds a new option to the array of options. This does work in Internet Explorer and is the more traditional Javascript way of adding options.
1 |
var options = $('#example').attr('options'); |
2 |
options[options.length] = new Option('Foo', 'foo', true, true); |
Using the final method above this last example shows how to replace the existing set of options with a new set, which may have been retrieved from an AJAX call or similar.
01 |
var newOptions = { |
02 |
'red' : 'Red', |
03 |
'blue' : 'Blue', |
04 |
'green' : 'Green', |
05 |
'yellow' : 'Yellow' |
06 |
}; |
07 |
var selectedOption = 'green'; |
08 |
09 |
var select = $('#example'); |
10 |
if(select.prop) { |
11 |
var options = select.prop('options'); |
12 |
} |
13 |
else { |
14 |
var options = select.attr('options'); |
15 |
} |
16 |
$('option', select).remove(); |
17 |
18 |
$.each(newOptions, function(val, text) { |
19 |
options[options.length] = new Option(text, val); |
20 |
}); |
21 |
select.val(selectedOption); |
Lines 1 to 7 define the new options with an associative array and the one which will be selected. This is what might have been retrieved from an AJAX call.
Lines 9 to 15 cache a handle to #example and its options. Note that from jQuery 1.6 you can't get a handle to the options using .attr('options') but it can be done with .prop('options') instead. This is why there's a test to see if .prop() is available.
Line 16 removes all the existing options.
Lines 18 to 20 loop through the new options and add them to the select box.
And finally line 21 sets the selected option.
There are some alternative methods to adding options to a select box with jQuery using various plug-ins and I may look at these in a future post.
http://www.electrictoolbox.com/jquery-add-option-select-jquery/
create proc [dbo].[backupdb]
as
begin
declare @str varchar(1000);
set @str = 'backup database runewcarsbd to disk =''D:\CarManage\db\'+convert(varchar(8),getdate(),112)+'runewcarsbd.bak'''
exec (@str)
end
--还原数据库
resotre database dbname
from disk = ''
update 表1 set from 表1,表2 where 条件
表的复制数据
1.select * into newtable from table
2.insert into table select table2
select identity(int,1,1),* into newtable from .. 这条语句有时挺管用的
就是这么简单-没有必要关心要那些表或配置表和对象的映射关系。在实践中,配置看起来如下:
<configuration>
<!-- 1 - Connection String(s) -->
<connectionStrings>
<add name="Northwind"
connectionString="Data Source=.\sqlexpress;Initial
Catalog=Northwind;Integrated Security=True"/>
</connectionStrings>
<configSections>
<!-- 2 - SubSonic section handler -->
<section name="SubSonicService"
type="SubSonic.SubSonicSection, SubSonic"/>
</configSections>
<!-- 3 - Point SubSonic at the appropriate data source(s) -->
<SubSonicService defaultProvider="Northwind">
<providers>
<add name="Northwind"
type="SubSonic.SqlDataProvider, SubSonic"
connectionStringName="Northwind"
generatedNamespace="Northwind"/>
</providers>
</SubSonicService>
</configuration>
来源:http://blog.csdn.net/ILOVEMSDN/archive/2009/02/15/3893027.aspx
select [name] from [sysdatabases]
use 当前库名
select [name] from [sysobjects] where [type] = 'u'
--u 表示用户表
select [name] from syscolumns where id= object_id('pcar')
object_id :返回架构范围内对象的数据库对象标识号。