小编Ash*_*ani的帖子

传递SqlDataReader作为转换参数

用于转换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数据?

c# sqldatareader type-conversion sqldatatypes

2
推荐指数
1
解决办法
3066
查看次数

检查字符串是否有斜杠

string testStr="thestringhasa\slash";

if(testStr.Contains("\"))
{
    //Code to process string with \
}
Run Code Online (Sandbox Code Playgroud)

我如何正确地测试以查看字符串是否包含反斜杠,当我尝试使用it语句时,如果在常量中显示新行.

.net c# regex windows string

2
推荐指数
2
解决办法
7639
查看次数

Javascript Regex:验证电话号码

我想验证一个必须以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会更好.

javascript regex jquery

1
推荐指数
1
解决办法
2437
查看次数

多次使用相同的选择与创建临时表

我有类似的代码

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)

sql sql-server

1
推荐指数
1
解决办法
1718
查看次数

SQL Server:按给定因子多次选择一行

我想从表中选择,但问题是,我有一个因子列,指示必须选择此行的次数(这是一个仅用于演示的示例表):

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)

sql sql-server

1
推荐指数
1
解决办法
522
查看次数

Isracard 的 RegEx(以色列卡)

我需要 Isracard(以色列信用卡)的正则表达式。

将非常感谢您的帮助,或者可能提供一些如何制作的信息。

Isracard 8-9 位数字的格式。

前任。卡片图片 - http://images.delcampe.com/img_large/auction/000/157/341/572_001.jpg

javascript c# regex

1
推荐指数
2
解决办法
1044
查看次数

退格(\ b)等同于快速语言

什么是\bswift中的等价物?我必须拆分从服务器收到的字符串\b

character special-characters ios swift

1
推荐指数
1
解决办法
3226
查看次数

getLayoutInflater().循环中的inflate()始终返回第一个视图

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 …

java android layout-inflater android-studio

1
推荐指数
1
解决办法
492
查看次数

?: Razor C# 中的条件

我正在将一个旧网站迁移到 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 是为了简单而创建的

c# asp.net asp.net-mvc razor asp.net-mvc-5

1
推荐指数
1
解决办法
1756
查看次数

将数组中的字符串项添加到对象列表中

我有一个字符串数组定义如下:

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

c# linq arrays arraylist

1
推荐指数
1
解决办法
93
查看次数