我有以下SQL语句(如果我在我的数据库中执行它,它会起作用):
IF EXISTS (SELECT * FROM dbo.PopularityPokemon WHERE Dex_ID = '445')
UPDATE dbo.PopularityPokemon SET TimesPicked = TimesPicked + 1
ELSE
INSERT into dbo.PopularityPokemon (Dex_ID, TimesPicked)VALUES('445', 1);
Run Code Online (Sandbox Code Playgroud)
我现在需要从代码隐藏中做到这一点.
我有以下两个参数:
private const int _pickCount = 1;
string dexID
Run Code Online (Sandbox Code Playgroud)
dexID是给我调用的函数的参数.
使用新连接并打开它来执行标准过程可以正常工作,但使用SQLCommand时可能会出现语法错误:
try
{
using (myConnection)
{
using (SqlCommand command = new SqlCommand())
{
command.Connection = myConnection;
command.CommandType = CommandType.Text;
command.CommandText = "IF EXISTS (SELECT * FROM dbo.PopularityPokemon WHERE Dex_ID = @Dex_ID) UPDATE dbo.PopularityPokemon SET TimesPicked = TimesPicked + @PickCount"
+ "ELSE"
+ "INSERT …Run Code Online (Sandbox Code Playgroud) 我有这种JSON,我怎么能转换为C#对象newtonsoft.
[["Newyork", "Goods & Services", "Description", "02/23/2016", "03/15/2016", "some info"]]
Run Code Online (Sandbox Code Playgroud) 我再次收到错误,说明没有与SQL查询匹配的行.
它指出:
位置0没有行.
要点:
firstnameTxt.Text = dt.Rows[0].ItemArray[1].ToString();
Run Code Online (Sandbox Code Playgroud)
以下是我的C#代码.
protected void Page_Load(object sender, EventArgs e)
{
if (Session["New"] != null)
{
redPnl.Visible = false;
UserNameSess.Text += Session["New"].ToString();
SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\v11.0; AttachDbFilename=C:\Users\Donald\Documents\Visual Studio 2013\Projects\DesktopApplication\DesktopApplication\Student_CB.mdf ;Integrated Security=True");
con.Open();
SqlDataAdapter sda = new SqlDataAdapter("Select Student_Username, Student_FName, Student_SName, Student_Email FROM Student Where Student_Username=@StuUsername", con);
sda.SelectCommand.Parameters.Add("@StuUsername", SqlDbType.VarChar).Value = UserNameSess.Text;
DataTable dt = new DataTable();
sda.Fill(dt);
if (dt.Rows.Count > 0)
usernameTxt.Text = dt.Rows[0].ItemArray[0].ToString();
firstnameTxt.Text = dt.Rows[0].ItemArray[1].ToString();
surnameTxt.Text = dt.Rows[0].ItemArray[2].ToString();
emailTxt.Text = dt.Rows[0].ItemArray[3].ToString();
dt.Clear();
} …Run Code Online (Sandbox Code Playgroud) 我有以下内容Combobox:
<ComboBox x:Name="Colors" FontSize="20">
<ComboBoxItem Background="#46d6db" Tag="#46d6db">Blue</ComboBoxItem>
<ComboBoxItem Background="#FDB75B" Tag="#FDB75B">Orange</ComboBoxItem>
<ComboBoxItem Background="#51B749" Tag="#51B749">Green</ComboBoxItem>
</ComboBox>
Run Code Online (Sandbox Code Playgroud)
现在您可以看到我有三个具有特定Tag属性的 ComboBoxItem。这里的标签属性就是颜色的值。
我需要知道的是:如何通过 Tag 属性获取特定 ComboBoxItem 的索引?
我将尝试更清楚地解释它:假设我有一个名为colorvalue 的字符串#FDB75B,现在我需要找到具有相同值的 ComboBox 项,并特别Tag获取 this 的位置。ComboBoxItem
string color = "#FDB75B";
//In this way I get the Tag property of the selected item
((ComboBoxItem)Colors.SelectedItem).Tag.ToString();
Run Code Online (Sandbox Code Playgroud)
现在我需要做相反的情况,找到ComboBoxItem带有标签的索引#FDB75B,并自动选择它,如下:
Colors.SelectedIndex = "element found";
Run Code Online (Sandbox Code Playgroud)
这可能吗?
我正在.NET 4.0(C#)中实现数据挖掘算法,LINQ将起作用,我需要一些帮助.
我有一个列表A和一个字典B.如何按值B排序A.例如A = {b, d, c}和B = {(b,2),(c,5),(d,1),(e,3)}.我需要排序A - > A = {c, b, d}.
我需要将条件设置为以下代码.
_orderStatus = Request.QueryString["order"] != null ? Request.QueryString["order"] : _orderStatus != "" ? _orderStatus : "pending";
Run Code Online (Sandbox Code Playgroud)
目前该条件仅适用于显示挂单.如何更改和添加以获得以下条件:
if Request.QueryString["order"] != null then
_orderStatus: "pending"
else
_orderStatus: "confirmed"
Run Code Online (Sandbox Code Playgroud)
谢谢
我尝试了一些不同的方法.我不确定是否可以使用上面的方法使用()语句或是否有其他方法.
public class Main
{
public Main()
{
using(Type t = new Type)
{
public void SomeFunction() {
t.toString()}
}
}
}
Run Code Online (Sandbox Code Playgroud) 我想从通过 for 循环生成的 NumericUpDown 中获取值,该循环将被迭代 N 次。但是在我的代码中,我只能获取第一个 NumericUpDown 值,并且它是通过单击按钮触发的。
显示 NumericUpDown 工具的代码:
for (int i = 0; i < 6; i++) // should be i < n
{
NumericUpDown note = new NumericUpDown();
note.Name = "Note" + i.ToString();
note.Location = new System.Drawing.Point(20, 40 + (40 * i));
note.Size = new System.Drawing.Size(40, 25);
note.Maximum = new decimal(new int[] { 10, 0, 0, 0 });
this.Controls.Add(note);
}
Run Code Online (Sandbox Code Playgroud)
获取值的代码:
var numericUpDown = this.Controls["note0"] as NumericUpDown;
var value = numericUpDown.Value;
MessageBox.Show(value.ToString());
Run Code Online (Sandbox Code Playgroud)
我怎样才能获得所有的值?非常感谢您的帮助。
我想从现在开始过去七天的日期.例如,当前日期是
02-10-2016, 像这样得到七天的日期
01-10-2016,30-09-2016,29-09-2016,28-09-2016,27-09-2016,26-09-2016
Run Code Online (Sandbox Code Playgroud)
我的代码
string dt = DateTime.Now.ToString("yyyy-MM-dd");
DateTime lastWeek = dt.AddDays(-7.0);
Run Code Online (Sandbox Code Playgroud) 所以我有一个像这样的字符串输入:
string pianist = "Johann Sebastian Bach";
Run Code Online (Sandbox Code Playgroud)
如何按空间分割它们,以便我可以访问,例如:
pianist[0] == "Johann"
pianist[1] == "Sebastian"
pianist[2] == "Bach"
Run Code Online (Sandbox Code Playgroud)
我试过
string test = pianist.Split(' ');
Run Code Online (Sandbox Code Playgroud)
但它不起作用。