将Xamarin连接到服务器信号r并获取数据sqldepeneCy

安德烈

新成员
加入
2017年10月21日
消息
1
编程经验
Beginner
大家好 !我有sqldependency,我通过javascript连接他的客户

C#:
[COLOR=#000000]        [/COLOR][COLOR=#000088]public[/COLOR][COLOR=#000088]static[/COLOR][COLOR=#660066]IEnumerable[/COLOR][COLOR=#666600]<[/COLOR][COLOR=#660066]Products[/COLOR][COLOR=#666600]>[/COLOR][COLOR=#660066]GetData[/COLOR][COLOR=#666600]()[/COLOR][COLOR=#000000]
        [/COLOR][COLOR=#666600]{[/COLOR][COLOR=#000000]

            [/COLOR][COLOR=#000088]using[/COLOR][COLOR=#666600]([/COLOR][COLOR=#000088]var[/COLOR][COLOR=#000000] connection [/COLOR][COLOR=#666600]=[/COLOR][COLOR=#000088]new[/COLOR][COLOR=#660066]SqlConnection[/COLOR][COLOR=#666600]([/COLOR][COLOR=#660066]ConfigurationManager[/COLOR][COLOR=#666600].[/COLOR][COLOR=#660066]ConnectionStrings[/COLOR][COLOR=#666600][[/COLOR][COLOR=#008800]"DataBase"[/COLOR][COLOR=#666600]].[/COLOR][COLOR=#660066]ConnectionString[/COLOR][COLOR=#666600]))[/COLOR][COLOR=#000000]
            [/COLOR][COLOR=#666600]{[/COLOR][COLOR=#000000]
                connection[/COLOR][COLOR=#666600].[/COLOR][COLOR=#660066]Open[/COLOR][COLOR=#666600]();[/COLOR][COLOR=#000000]
                [/COLOR][COLOR=#000088]using[/COLOR][COLOR=#666600]([/COLOR][COLOR=#660066]SqlCommand[/COLOR][COLOR=#000000] command [/COLOR][COLOR=#666600]=[/COLOR][COLOR=#000088]new[/COLOR][COLOR=#660066]SqlCommand[/COLOR][COLOR=#666600](@[/COLOR][COLOR=#008800]"SELECT [Guests] FROM  [1]"[/COLOR][COLOR=#666600],[/COLOR][COLOR=#000000] connection[/COLOR][COLOR=#666600]))[/COLOR][COLOR=#000000]
                [/COLOR][COLOR=#666600]{[/COLOR][COLOR=#000000]
                    [/COLOR][COLOR=#880000]// Make sure the command object does not already have[/COLOR][COLOR=#000000]
                    [/COLOR][COLOR=#880000]// a notification object associated with it.[/COLOR][COLOR=#000000]
                    command[/COLOR][COLOR=#666600].[/COLOR][COLOR=#660066]Notification[/COLOR][COLOR=#666600]=[/COLOR][COLOR=#000088]null[/COLOR][COLOR=#666600];[/COLOR][COLOR=#000000]
                    [/COLOR][COLOR=#660066]SqlDependency[/COLOR][COLOR=#666600].[/COLOR][COLOR=#660066]Start[/COLOR][COLOR=#666600]([/COLOR][COLOR=#660066]ConfigurationManager[/COLOR][COLOR=#666600].[/COLOR][COLOR=#660066]ConnectionStrings[/COLOR][COLOR=#666600][[/COLOR][COLOR=#008800]"DataBase"[/COLOR][COLOR=#666600]].[/COLOR][COLOR=#660066]ConnectionString[/COLOR][COLOR=#666600]);[/COLOR][COLOR=#000000]
                    [/COLOR][COLOR=#660066]SqlDependency[/COLOR][COLOR=#000000] dependency [/COLOR][COLOR=#666600]=[/COLOR][COLOR=#000088]new[/COLOR][COLOR=#660066]SqlDependency[/COLOR][COLOR=#666600]([/COLOR][COLOR=#000000]command[/COLOR][COLOR=#666600]);[/COLOR][COLOR=#000000]
                    dependency[/COLOR][COLOR=#666600].[/COLOR][COLOR=#660066]OnChange[/COLOR][COLOR=#666600]+=[/COLOR][COLOR=#000088]new[/COLOR][COLOR=#660066]OnChangeEventHandler[/COLOR][COLOR=#666600]([/COLOR][COLOR=#000000]dependency_OnChange[/COLOR][COLOR=#666600]);[/COLOR][COLOR=#000000]

                    [/COLOR][COLOR=#000088]if[/COLOR][COLOR=#666600]([/COLOR][COLOR=#000000]connection[/COLOR][COLOR=#666600].[/COLOR][COLOR=#660066]State[/COLOR][COLOR=#666600]==[/COLOR][COLOR=#660066]ConnectionState[/COLOR][COLOR=#666600].[/COLOR][COLOR=#660066]Closed[/COLOR][COLOR=#666600])[/COLOR][COLOR=#000000]
                        connection[/COLOR][COLOR=#666600].[/COLOR][COLOR=#660066]Open[/COLOR][COLOR=#666600]();[/COLOR][COLOR=#000000]

                    [/COLOR][COLOR=#000088]using[/COLOR][COLOR=#666600]([/COLOR][COLOR=#000088]var[/COLOR][COLOR=#000000] reader [/COLOR][COLOR=#666600]=[/COLOR][COLOR=#000000] command[/COLOR][COLOR=#666600].[/COLOR][COLOR=#660066]ExecuteReader[/COLOR][COLOR=#666600]())[/COLOR][COLOR=#000000]
                        [/COLOR][COLOR=#000088]return[/COLOR][COLOR=#000000] reader[/COLOR][COLOR=#666600].[/COLOR][COLOR=#660066]Cast[/COLOR][COLOR=#666600]<[/COLOR][COLOR=#660066]IDataRecord[/COLOR][COLOR=#666600]>()[/COLOR][COLOR=#000000]
                            [/COLOR][COLOR=#666600].[/COLOR][COLOR=#660066]Select[/COLOR][COLOR=#666600]([/COLOR][COLOR=#000000]x [/COLOR][COLOR=#666600]=>[/COLOR][COLOR=#000088]new[/COLOR][COLOR=#660066]Products[/COLOR][COLOR=#666600]()[/COLOR][COLOR=#000000]
                            [/COLOR][COLOR=#666600]{[/COLOR][COLOR=#000000]
                                [/COLOR][COLOR=#660066]Guests[/COLOR][COLOR=#666600]=[/COLOR][COLOR=#000000] x[/COLOR][COLOR=#666600].[/COLOR][COLOR=#660066]GetString[/COLOR][COLOR=#666600]([/COLOR][COLOR=#006666]0[/COLOR][COLOR=#666600]),[/COLOR][COLOR=#000000]
                            [/COLOR][COLOR=#666600]}).[/COLOR][COLOR=#660066]ToList[/COLOR][COLOR=#666600]();[/COLOR][COLOR=#000000]


                [/COLOR][COLOR=#666600]}[/COLOR][COLOR=#000000]
            [/COLOR][COLOR=#666600]}[/COLOR][COLOR=#000000]
        [/COLOR][COLOR=#666600]}[/COLOR]

C#:
[COLOR=#000000]          [/COLOR][COLOR=#000088]function[/COLOR][COLOR=#000000] getData[/COLOR][COLOR=#666600]()[/COLOR][COLOR=#666600]{[/COLOR][COLOR=#000000]
              [/COLOR][COLOR=#000088]var[/COLOR][COLOR=#000000] $tbl [/COLOR][COLOR=#666600]=[/COLOR][COLOR=#000000] $[/COLOR][COLOR=#666600]([/COLOR][COLOR=#008800]'#tbl'[/COLOR][COLOR=#666600]);[/COLOR][COLOR=#000000]
              $[/COLOR][COLOR=#666600].[/COLOR][COLOR=#000000]ajax[/COLOR][COLOR=#666600]({[/COLOR][COLOR=#000000]
                  url[/COLOR][COLOR=#666600]:[/COLOR][COLOR=#008800]'index.aspx/GetData'[/COLOR][COLOR=#666600],[/COLOR][COLOR=#000000]
                  contentType[/COLOR][COLOR=#666600]:[/COLOR][COLOR=#008800]"application/json; charset=utf-8"[/COLOR][COLOR=#666600],[/COLOR][COLOR=#000000]
                  dataType[/COLOR][COLOR=#666600]:[/COLOR][COLOR=#008800]"json"[/COLOR][COLOR=#666600],[/COLOR][COLOR=#000000]
                  type[/COLOR][COLOR=#666600]:[/COLOR][COLOR=#008800]"POST"[/COLOR][COLOR=#666600],[/COLOR][COLOR=#000000]
                  success[/COLOR][COLOR=#666600]:[/COLOR][COLOR=#000088]function[/COLOR][COLOR=#666600]([/COLOR][COLOR=#000000]data[/COLOR][COLOR=#666600])[/COLOR][COLOR=#666600]{[/COLOR][COLOR=#000000]
                      [/COLOR][COLOR=#000088]debugger[/COLOR][COLOR=#666600];[/COLOR][COLOR=#000000]
                      [/COLOR][COLOR=#000088]if[/COLOR][COLOR=#666600]([/COLOR][COLOR=#000000]data[/COLOR][COLOR=#666600].[/COLOR][COLOR=#000000]d[/COLOR][COLOR=#666600].[/COLOR][COLOR=#000000]length [/COLOR][COLOR=#666600]>[/COLOR][COLOR=#006666]0[/COLOR][COLOR=#666600])[/COLOR][COLOR=#666600]{[/COLOR][COLOR=#000000]
                          [/COLOR][COLOR=#000088]var[/COLOR][COLOR=#000000] newdata [/COLOR][COLOR=#666600]=[/COLOR][COLOR=#000000] data[/COLOR][COLOR=#666600].[/COLOR][COLOR=#000000]d[/COLOR][COLOR=#666600];[/COLOR][COLOR=#000000]
                          $tbl[/COLOR][COLOR=#666600].[/COLOR][COLOR=#000000]empty[/COLOR][COLOR=#666600]();[/COLOR][COLOR=#000000]
                          $tbl[/COLOR][COLOR=#666600].[/COLOR][COLOR=#000000]append[/COLOR][COLOR=#666600]([/COLOR][COLOR=#008800]' <tr><th>ID</th><th>Name</th><th>Last Executed Date</th><th>Status</th></tr>'[/COLOR][COLOR=#666600]);[/COLOR][COLOR=#000000]
                          [/COLOR][COLOR=#000088]var[/COLOR][COLOR=#000000] rows [/COLOR][COLOR=#666600]=[/COLOR][COLOR=#666600][];[/COLOR][COLOR=#000000]
                          [/COLOR][COLOR=#000088]for[/COLOR][COLOR=#666600]([/COLOR][COLOR=#000088]var[/COLOR][COLOR=#000000] i [/COLOR][COLOR=#666600]=[/COLOR][COLOR=#006666]0[/COLOR][COLOR=#666600];[/COLOR][COLOR=#000000] i [/COLOR][COLOR=#666600]<[/COLOR][COLOR=#000000] newdata[/COLOR][COLOR=#666600].[/COLOR][COLOR=#000000]length[/COLOR][COLOR=#666600];[/COLOR][COLOR=#000000] i[/COLOR][COLOR=#666600]++)[/COLOR][COLOR=#666600]{[/COLOR][COLOR=#000000]
                              rows[/COLOR][COLOR=#666600].[/COLOR][COLOR=#000000]push[/COLOR][COLOR=#666600]([/COLOR][COLOR=#008800]' <tr><td>'[/COLOR][COLOR=#666600]+[/COLOR][COLOR=#000000] newdata[/COLOR][COLOR=#666600][[/COLOR][COLOR=#000000]i[/COLOR][COLOR=#666600]].[/COLOR][COLOR=#660066]Guests[/COLOR][COLOR=#666600]+[/COLOR][COLOR=#008800]'</td></tr>'[/COLOR][COLOR=#666600]);[/COLOR][COLOR=#000000]
                          [/COLOR][COLOR=#666600]}[/COLOR][COLOR=#000000]
                          $tbl[/COLOR][COLOR=#666600].[/COLOR][COLOR=#000000]append[/COLOR][COLOR=#666600]([/COLOR][COLOR=#000000]rows[/COLOR][COLOR=#666600].[/COLOR][COLOR=#000000]join[/COLOR][COLOR=#666600]([/COLOR][COLOR=#008800]''[/COLOR][COLOR=#666600]));[/COLOR][COLOR=#000000]
                      [/COLOR][COLOR=#666600]}[/COLOR][COLOR=#000000]
                  [/COLOR][COLOR=#666600]}[/COLOR][COLOR=#000000]
              [/COLOR][COLOR=#666600]});[/COLOR][COLOR=#000000]
          [/COLOR][COLOR=#666600]}[/COLOR]


我怎样才能连接到 index.aspx / getdat.a by Xamarin ?
 
最佳 底部