如何在Visual Studio Windows窗体中将此PHP代码转换为C# [英] How can I convert this PHP code to C# in Visual Studio Windows Form

查看:91
本文介绍了如何在Visual Studio Windows窗体中将此PHP代码转换为C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Php有一些了解,但最近我开始使用Visual Studio,我想知道如何将代码转换为Visual Studio。我想创建一个组合框,打印出主要类别,然后是它下面的子类别,然后是它下面的项目,依此类推,直到所有主要类别都完成。我不知道如何在C#上编写它们所以我首先在PHP中创建代码并尝试剖析它们。



到目前为止,我在Visual Studio中的当前代码是:

I have a somewhat okay knowledge in Php but I recently started Visual Studio and I was wondering how would I go about converting my code to Visual Studio. I wanted to create a combo box that will print out the main category then the sub category under it then the items under it and so on until all main categories are finished. I had no idea how to write them on C# so I first created the code in PHP and tried to dissect them.

So far my current code in Visual Studio is:

private void Form1_Load(object sender, EventArgs e)
{
sc.Open();

//For Main Category
SqlCommand get_maincategory_name = new SqlCommand("SELECT * FROM maincategory", sc);
SqlDataReader dr2 = get_maincategory_name.ExecuteReader();
while (dr2.Read())
{
comboBox1.Items.Add(dr2["maincategory_name"].ToString());

//For Sub Category
SqlCommand get_subcategory_name = new SqlCommand("SELECT * FROM subcategory WHERE maincategory_id='1'", sc);
SqlDataReader dr3 = get_subcategory_name.ExecuteReader();
while (dr3.Read())
{
comboBox1.Items.Add("--" + dr3["subcategory_name"].ToString());

//For Inventory
SqlCommand get_inventory_name = new SqlCommand("SELECT * FROM inventory WHERE subcategory_id='1'", sc);
SqlDataReader dr4 = get_inventory_name.ExecuteReader();
while (dr4.Read())
{
comboBox1.Items.Add("----" + dr4["item_name"].ToString());
}
}
}
sc.Close();
}





我的PHP代码如下所示:



My PHP code looks like this:

echo "<select>";

// FOR MAIN CATEGORY
$maincategory_query = mysqli_query($con,"SELECT * FROM maincategory") or mysqli_error();
while($got = mysqli_fetch_assoc($maincategory_query))
{
$maincategory_id = $got['maincategory_id'];
$maincategory_name = $got['maincategory_name'];
echo "<option disabled>$maincategory_name</option>";

// FOR SUB CATEGORY
$subcategory_query = mysqli_query($con,"SELECT * FROM subcategory WHERE maincategory_id='$maincategory_id'") or mysqli_error();
while($got = mysqli_fetch_assoc($subcategory_query))
{
$subcategory_id = $got['subcategory_id'];
$subcategory_name = $got['subcategory_name'];
echo "<option disabled>--$subcategory_name</option>";

// FOR ITEM
$item_query = mysqli_query($con,"SELECT * FROM item WHERE subcategory_id='$subcategory_id'") or mysqli_error();
while($got = mysqli_fetch_assoc($item_query))
{
$item_id = $got['item_id'];
$item_name = $got['item_name'];
echo "<option>----$item_name</option>";
}
}
}
echo "</select>";





我遇到的问题:

1.它只显示第一个主要类别名称而没有别的。

2.我正在弄清楚如何放入dr2 [maincategory_id](替换1)在WHERE下面的sql语句中,但是我无法弄清楚它不会被解释为字符串的语法是什么。

3.我不知道如何禁用(或使其成为只读)组合框的某些部分。



The problems I'm having:
1. It's only showing the first main category name and nothing else.
2. I'm currently figuring out how to put dr2["maincategory_id"] (to replace the 1) inside the sql statement under WHERE but I'm having trouble figuring out what's the syntax on how it wouldn't be interpreted as a string.
3. I don't know how to disable(or to make read-only) certain parts of the combo box.

推荐答案

maincategory_query = mysqli_query(
maincategory_query = mysqli_query(


con, SELECT * FROM maincategory mysqli_error();
while(
con,"SELECT * FROM maincategory") or mysqli_error(); while(


got = mysqli_fetch_assoc(
got = mysqli_fetch_assoc(


这篇关于如何在Visual Studio Windows窗体中将此PHP代码转换为C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆