用于转换SqlDataReader的数据我做这些(常见数据类型的示例):
string name = reader["name"].ToString(); //for string
int i = 0; i = int.TryParse(reader["i"].ToString(), out i); //for int
int i = reader.GetInt32(reader.GetOrdinal("i")); //or this again for int
bool b = reader.GetBoolean(reader.GetOrdinal("b")); // for boolean
Run Code Online (Sandbox Code Playgroud)
我想用这些函数创建一个类:
public static class gd{
public static bool Bool(SqlDataReader rd, string name)
{
return rd.GetBoolean(rd.GetOrdinal(name));
}
public static int Int(SqlDataReader rd, string name)
{
int i=0;
i = int.TryParse(reader["i"].ToString(), out i);
return i;
}
}
Run Code Online (Sandbox Code Playgroud)
然后使用:
int i=c.Int(reader,"i");
bool b=c.Bool(reader,"b");
DateTime dt = c.Date(reader,"dt");
Run Code Online (Sandbox Code Playgroud)
我想知道将datareader作为参数传递是个好主意吗?任何人都有更好的想法来铸造datareader数据?
string testStr="thestringhasa\slash";
if(testStr.Contains("\"))
{
//Code to process string with \
}
Run Code Online (Sandbox Code Playgroud)
我如何正确地测试以查看字符串是否包含反斜杠,当我尝试使用it语句时,如果在常量中显示新行.
我想验证一个必须以09开头的11位电话号码(即09123456789),使用javascript进行客户端检查.
这是我的代码:
function validatePhone(number) {
var re = /^09[0-9]{9}$/;
return re.test(number);
}
Run Code Online (Sandbox Code Playgroud)
据我所知,它最初工作正常,但现在它对我使用的任何数字都返回无效.有谁知道我的代码有什么问题?顺便说一下,当我使用jQuery时,如果有一个更好的方法,jquery会更好.
我有类似的代码
select count(*) from(
select t1.col1, t1.col2, t1,col3, t2.col2 from table1 t1
left join table2 t2 on t1.col1=t2.col1) x
select * from(
select t1.col1, t1.col2, t1,col3, t2.col2 from table1 t1
left join table2 t2 on t1.col1=t2.col1) x
where x.col1 > 10
Run Code Online (Sandbox Code Playgroud)
我选择并加入具有相同列的相同表两次。如果我这样做:
declare @table table(col1 int,col2 int,col3 varchar,col4 int)
insert into @table(col1,col2,col3,col4) select * from (
select t1.col1, t1.col2, t1,col3, t2.col2 from table1 t1
left join table2 t2 on t1.col1=t2.col1
) x
select count(*) from @table
select * from @table …Run Code Online (Sandbox Code Playgroud) 我想从表中选择,但问题是,我有一个因子列,指示必须选择此行的次数(这是一个仅用于演示的示例表):
ID Factor Count
-------------------------------
1 1 235
2 2 345
3 2 214
4 3 95
5 1 135
6 1 750
Run Code Online (Sandbox Code Playgroud)
查询:
select top 6
[id], [count]
from
table
order by
id --somewhere in here I must take factor into consideration
Run Code Online (Sandbox Code Playgroud)
结果必须是:
ID Count
---------------------
1 235
2 345
2 345
3 214
3 214
4 135
Run Code Online (Sandbox Code Playgroud) 我需要 Isracard(以色列信用卡)的正则表达式。
将非常感谢您的帮助,或者可能提供一些如何制作的信息。
Isracard 8-9 位数字的格式。
前任。卡片图片 - http://images.delcampe.com/img_large/auction/000/157/341/572_001.jpg
什么是\bswift中的等价物?我必须拆分从服务器收到的字符串\b?
将tics有3个项目.以下代码创建3个故障单项,但始终设置TextView第一个故障单的s 的文本.
public void onSuccess(int i, Header[] headers, byte[] bytes) {
progress.dismiss();
String response = new String(bytes);
try{
JSONObject obj = new JSONObject(response);
JSONArray tics = obj.getJSONArray("tickets");
LinearLayout p = (LinearLayout)findViewById(R.id.tickets);
for(int j = 0;j<tics.length();j++){
LinearLayout t =(LinearLayout) getLayoutInflater().inflate(R.layout.ticket_row, p);
TextView topic = (TextView)t.findViewWithTag("topic");
TextView section = (TextView)t.findViewWithTag("section");
TextView datetime = (TextView)t.findViewWithTag("datetime");
JSONObject item = tics.getJSONObject(j);
Toast.makeText(getApplicationContext(),item.getString("Caption") ,Toast.LENGTH_LONG).show();
topic.setText(item.getString("Caption"));
datetime.setText(item.getString("DateString"));
section.setText(item.getString("Section"));
}
}catch (Exception e){}
}
Run Code Online (Sandbox Code Playgroud)
在以下代码中:
LinearLayout t =(LinearLayout) getLayoutInflater().inflate(R.layout.ticket_row, p);
Run Code Online (Sandbox Code Playgroud)
不t应该膨胀View …
我正在将一个旧网站迁移到 ASP.Net MVC 5,我有一个这样的链接:
<a href="/contact"><%=User.Identity.IsAuthenticated?"Support":"Contact Us"%></a>
Run Code Online (Sandbox Code Playgroud)
我用谷歌搜索并尝试了几件事,最终得到了以下代码:
<a href="/contact">@if{User.Identity.IsAuthenticated){@Html.Raw("Support");}else{@HtmlRaw("Contact Us");}</a>
Run Code Online (Sandbox Code Playgroud)
但这似乎不是解决方案,因为它比第一个复杂得多,而 Razor 是为了简单而创建的
我有一个字符串数组定义如下:
string[] items = { "Item 1", "Item 2", "Item 3", "Item 4"};
Run Code Online (Sandbox Code Playgroud)
然后我将模型定义为:
public class ItemModel {
public int Id { get; set; }
public string ItemName { get; set; }
public bool IsItem { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我已将列表定义为:
var listItems = new List<ItemModel>();
Run Code Online (Sandbox Code Playgroud)
我想将数组中的项添加items到对象列表中listItems.我想要添加项目ItemName