我第一次用 vb.net 编码,想从数据集中读取值。
为此,我编码如下,但不起作用:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'------------------------------Load Name------------------'
Try
Dim strcon As String = ConfigurationManager.ConnectionStrings("ConnStringDb").ConnectionString
Dim i As Integer
Dim con As New SqlConnection(strcon)
da = New SqlDataAdapter("select empName from empMaster_VB", con)
ds = New DataSet()
da.Fill(ds)
For(i=0;i<ds.
Catch ex As Exception
End Try
End Sub
Run Code Online (Sandbox Code Playgroud)
当我们从 C# 中的数据集获取值时,我尝试使用 VB(从 for 循环)作为,
for(int i=0;i<ds.Tables[0].Rows.Count;i++)
{
int someVar=int.parse(ds.Tables[0].Rows[i][0].toString());
}
Run Code Online (Sandbox Code Playgroud)
但它不能像我上面编码的那样在 vb.net 中工作,
请帮我。
我写了一个存储过程: -
CREATE PROCEDURE GET_USERSTORYDATA_EXISTS
@MyWizardUserStoryId INT
,@ProjectId INT
,@StoryTitle NVARCHAR(MAX)
AS
BEGIN
SET NOCOUNT ON;
IF EXISTS (SELECT 1 FROM USERSTORY WHERE [MyWizardUserStoryId]=@MyWizardUserStoryId AND ProjectId=@ProjectId)
BEGIN
IF EXISTS (SELECT 1 FROM USERSTORY WHERE [MyWizardUserStoryId]=@MyWizardUserStoryId AND ProjectId=@ProjectId AND Title=@StoryTitle)
BEGIN
SELECT 0;
END
ELSE
BEGIN
SELECT 1;
END
END
ELSE
BEGIN
SELECT 1;
END
END
GO
Run Code Online (Sandbox Code Playgroud)
我通过Entity框架使用了这个程序: -
List<Int32>lst=context.GET_USERSTORYDATA_EXISTS(MyWizardUserStoryId,ProjectId,storyTitle);
Run Code Online (Sandbox Code Playgroud)
但它给我的错误: -
Can not implicitly convert type 'ObjectResult<int?>' to List<int>
Run Code Online (Sandbox Code Playgroud) 我有以下类结构:
class Child
{
public List<ParentData> ParentData { get; set; }
}
class ParentData
{
public string FatherName {get;set;}
public string MotherName {get;set;}
public List<GrandParentData> GrandParentData{ get; set; }
}
class GrandParentData
{
public string GrandFatherName {get;set;}
public string GrandMotherName {get;set;}
}
Run Code Online (Sandbox Code Playgroud)
当我想填补这个:
foreach (var item in res)
{
obj.StoryData.Add(
new StoryData
{
FatherName = item.FatherName,
MotherName = item.Description,
GrandParentData = new List<GrandParentData().Add(
new GrandParentData
{
GrandFatherName = "",
GrandMotherName = ""
}
);
}
);
}
Run Code Online (Sandbox Code Playgroud)
当我尝试将数据添加到GrandParentList列表时,这给了我错误:
无法将类型void隐式转换为List
我需要改变我的班级结构吗?我应该对代码进行哪些编辑?
我有桌子:
Bonus Value
500 1400
1500 177
1800 453
1200 100
800 2500
200 50
780 740
Run Code Online (Sandbox Code Playgroud)
我想打印列的总和,以最大值为准.
我试过以下:
select
case when sum(bonus)>sum(Value) then sum(bonus) end
case when sum(Value)>sum(bonus) then sum(Value) end
from emp
Run Code Online (Sandbox Code Playgroud)
但我没有得到结果.
错误:
Msg 156, Level 15, State 1, Line 3
Incorrect syntax near the keyword 'case'.
Run Code Online (Sandbox Code Playgroud) 我试图在数据库中插入一个问题,表中的字段为nvarchar(max)(sql server 2008 r2)
代码如下:
Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click
gc.ExecuteCommand("insert into QuestionMaster values('" & txtQuestion.Text & "','" & ViewState("ClientID") & "','" & ViewState("KioskID") & "')")
Response.Write("<script type='text/javascript' language='javascript'>alert('Question Added Sucessfully!!!')</script>")
BindGrid()
End Sub
Run Code Online (Sandbox Code Playgroud)
当我插入任何字符串时:
what's your name?
Run Code Online (Sandbox Code Playgroud)
然后它给了我错误:
's'附近的语法不正确.字符串')'后面的未闭合引号.
如果我只是提供字符串:
What is your name?
Run Code Online (Sandbox Code Playgroud)
然后它不会给我错误.
请帮我.
我直接将android连接到SQLServer(我知道它不推荐)
我写了以下代码:
public class MainActivity extends Activity {
String dbName = "AndroidDB";
String serverip="10.0.2.2";
String serverport="1433";
//String url = "jdbc:sqlserver://14GRAFICALI\\MSSQLSERVER2008;databaseName="+dbName+"";
//String url ="jdbc:sqlserver://14GRAFICALI\\MSSQLSERVER2008;databaseName=AndroidDB;integratedSecurity=true";
String url ="jdbc:sqlserver://14GRAFICALI;instanceName=\\MSSQLSERVER2008;DatabaseName=AndroidDB;integratedSecurity=true";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView tvData=(TextView)findViewById(R.id.tvSelectedData);
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();
Class.forName("javax.sql.XAConnection").newInstance();
Connection conn =DriverManager.getConnection(url);
Statement statement=conn.createStatement();
ResultSet resultSet=statement.executeQuery("select * from UserMaster");
while(resultSet.next()){
tvData.setText(" Data1 : "+resultSet.getString(1)+" Data 2 : "+resultSet.getNString(2));
}
} catch (Exception e) {
e.printStackTrace();
tvData.setText(e.getMessage());
}
}
Run Code Online (Sandbox Code Playgroud)
在此之前,我没有这条线:
Class.forName("javax.sql.XAConnection").newInstance();
Run Code Online (Sandbox Code Playgroud)
但它给了我一个例外:
09-07 15:12:20.911: E/dalvikvm(1293): Could not find class 'javax.sql.XAConnection', …Run Code Online (Sandbox Code Playgroud) 我在android中使用jdbc(Aware not recomended)
我有以下代码:
public int CheckUser(String uName,String password)
{
try {
String sql="select uid from UserMaster where username='"+uName+"' and password='"+password+"'";
statement = conn.createStatement();
resultSet = statement.executeQuery(sql);
int value=0;
if (resultSet.next()) {
value=resultSet.getInt(1);
}
return value;
}
catch (Exception e)
{
e.printStackTrace();
return 0;
}
}
Run Code Online (Sandbox Code Playgroud)
我得到空指针异常 statement = conn.createStatement();
logcat的:
09-12 11:04:14.543: W/KeyCharacterMap(483): No keyboard for id 0
09-12 11:04:14.553: W/KeyCharacterMap(483): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
09-12 11:04:51.173: W/System.err(483): java.lang.NullPointerException
09-12 11:04:51.194: W/System.err(483): at com.example.messagesql.gaSQLConnect.CheckUser(gaSQLConnect.java:69)
09-12 11:04:51.213: W/System.err(483): at com.example.messagesql.Login$UserLogin.doInBackground(Login.java:109) …Run Code Online (Sandbox Code Playgroud) 我有一个字符串列表.
我想在其中删除一个如下:
settings.RecentSearches.Keys.Remove(itemToAdd.Key);
settings.RecentSearches.Keys.Add(itemToAdd.Key);
Run Code Online (Sandbox Code Playgroud)
错误:
Mutating a key collection derived from a dictionary is not allowed.
Run Code Online (Sandbox Code Playgroud)
我想在其中添加和删除值.
我能做什么?
我想获得点击按钮的ID,因为我的表单上有4-5个按钮.
<button type="submit" style="height: 30px" id="btnHelp" name="btnHelp" onclick="ShowHelp(2);return false;">Help</button>
<button type="button" style="height: 30px" id="btnClose" name="btnClose" onclick="Close();return false;">Close</button>
<button type="button" style="height: 30px" id="btnSave" name="btnSave" onclick="Save();return false;">Close</button>
...............................
Run Code Online (Sandbox Code Playgroud)
无论哪个按钮点击,我只想获得该按钮的ID.
$(function () {
var id = $(this).attr('id');
alert(id);
})
Run Code Online (Sandbox Code Playgroud)
还有
$("input").click(function (event) {
var urlid = $(this).attr('id')
alert(urlid);
})
Run Code Online (Sandbox Code Playgroud)
但我得到的警报是未定义的.
如何点击按钮的ID?
请帮我.
我有字符串:
string sku= "plmca60 5";
Run Code Online (Sandbox Code Playgroud)
我只想用逗号替换第一个空格.因此我试过:
sku.replace(" ",",");
Run Code Online (Sandbox Code Playgroud)
但它给了我:
sku="plmca60,,,,,5";
Run Code Online (Sandbox Code Playgroud)
因为字符串中有五个空格.但是我想要替换第一次出现的空白区域;
sku="plmca60, 5"
Run Code Online (Sandbox Code Playgroud)
我怎么能这样做?
我有下面的示例 javascript 数组对象 -
[ {id:"B1",name:"Belacost",group:"Quim"},
{id:"B1",name:"Medtown",group:"Bik"},
{id:"B1",name:"Regkim",group:"Dum"},
{id:"C1",name:"CSet",group:"Core"},
{id:"D1",name:"Merigo",group:"Dian"},
{id:"D1",name:"Chilland",group:"Ground"},
{id:"N1",name:"Fiwkow",group:"Vig"},
]
Run Code Online (Sandbox Code Playgroud)
在这个数组中,如果重复,我想将 id 设为空。
Eg. [ {id:"B1",name:"Belacost",group:"Quim"}, //id is here since this is first time
{id:"",name:"Medtown",group:"Bik"}, //id is blank since we already have B1
{id:"",name:"Regkim",group:"Dum"},
{id:"C1",name:"CSet",group:"Core"},
{id:"D1",name:"Merigo",group:"Dian"}, // id is here since D1 is first time
{id:"",name:"Chilland",group:"Ground"}, //id is empty since we already have id D1
{id:"N1",name:"Fiwkow",group:"Vig"},
]
Run Code Online (Sandbox Code Playgroud)
我尝试通过 map 实现它,但找不到重复 id。