我在此代码中有错误,紧急 [英] i have error in this code ,its urgent

查看:56
本文介绍了我在此代码中有错误,紧急的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在此代码中有错误,其紧急
请plzzzzzzzz亲自解决此错误


i have error in this code ,its urgent
plzzzzzzzz anbody solve this error


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        protected DataSet PDataset(string select_statement)
        {
            SqlConnection con = new SqlConnection("server=192.168.0.50\\CIODEVDB;user id=sa;password=epm@3108;database=Parent");
            SqlDataAdapter ad = new SqlDataAdapter(select_statement, con);
            DataSet ds = new DataSet();
            ad.Fill(ds);
            con.Close();
            return ds;
        }


        public void Load_tree2()
        {
            SqlConnection con = new SqlConnection("server=192.168.0.50\\CIODEVDB;user id=sa;password=epm@3108;database=Parent");


            con.Open();

            DataSet ds = PDataset("Select * from details");
            treeView1.Nodes.Clear();
            foreach (DataRow dr in ds.Tables[0].Rows)
            {

                if ((Convert.ToInt32(dr["parentname"].ToString()) == 0))
                {
                    TreeNode tnParent = new TreeNode();
                    tnParent.Text = dr["name"].ToString();
                    string value = dr["id"].ToString();
                    tnParent.Expand();
                    treeView1.Nodes.Add(tnParent);
                    FillChild(tnParent, value);
                    treeView1.ExpandAll();
                }
            }
        }

        public int FillChild(TreeNode parent, string ID)
        {
            SqlConnection con = new SqlConnection("server=192.168.0.50\\CIODEVDB;user id=sa;password=epm@3108;database=Parent");

            con.Open();
            DataSet ds = PDataset("SELECT * FROM details WHERE ParentID =" + ID);
            if (ds.Tables[0].Rows.Count > 0)
            {

                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    TreeNode child = new TreeNode();
                    child.Text = dr["name"].ToString().Trim();
                    string temp = dr["id"].ToString();
                    child.Collapse();
                    parent.Nodes.Add(child);
                    FillChild(child, temp);
                }
                return 0;
            }
            else
            {
                return 0;
            }

        }

        private void Form1_Load(object sender, EventArgs e)
        {
            Load_tree2();

        }

        private void btnadd_Click(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection("server=192.168.0.50\\CIODEVDB;user id=sa;password=epm@3108;database=Parent");

            con.Open();


            string MyString = "INSERT INTO details(name,parentname)values('" + textBox1.Text + "'," + getNodeid(treeView1.SelectedNode.ToString()) + ")";

            SqlCommand MyCmd = new SqlCommand(MyString, con);


            MyCmd.ExecuteNonQuery();

            TreeNode childnode = new TreeNode(textBox1.Text);
            treeView1.SelectedNode.Nodes.Add(childnode);
            treeView1.ExpandAll();
            textBox1.Clear();
            con.Close();
            Load_tree2();
            textBox1.Clear();

        }

        private int getNodeid(string nodename)
        {
            string node = nodename.Substring(10);
            SqlConnection con = new SqlConnection("server=192.168.0.50\\CIODEVDB;user id=sa;password=epm@3108;database=Parent");
            con.Open();
            string MyString = "select ID from details where name='" + node + "'";

            SqlCommand MyCmd = new SqlCommand(MyString, con);
            SqlDataAdapter da = new SqlDataAdapter(MyCmd);
            DataTable dt = new DataTable();
            da.Fill(dt);
            string aa = dt.Rows[0][0].ToString();

            con.Close();
            return Convert.ToInt32(aa);

        }

        private void btnremove_Click(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection("server=192.168.0.50\\CIODEVDB;user id=sa;password=epm@3108;database=Parent");
            con.Open();

            string MyString = "Delete from details where name= '" + treeView1.SelectedNode.ToString() + "'";

            SqlCommand MyCmd = new SqlCommand(MyString, con);
            SqlDataAdapter da = new SqlDataAdapter(MyCmd);
            MyCmd.ExecuteNonQuery();
            Load_tree2();

            con.Close();
            //treeView1.SelectedNode.Remove();
        }





        private void btnparent_Click(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection("server=192.168.0.50\\CIODEVDB;user id=sa;password=epm@3108;database=Parent");
            con.Open();
            string MyString = "INSERT INTO details(name)values('" + textBox1.Text + "')";
            SqlCommand MyCmd = new SqlCommand(MyString, con);
            TreeNode parentnode = new TreeNode(textBox1.Text);
            treeView1.SelectedNode.Nodes.Add(parentnode);
            MyCmd.ExecuteNonQuery();

            con.Close();
            textBox1.Clear();
        }
    }
}

推荐答案

答案可能很有趣,但请允许我提供帮助


立即尝试此代码

the answer may be funny but let me help


try this code now

string MyString = "INSERT INTO details(name,parentname) values('" + textBox1.Text + "','" + getNodeid(treeView1.SelectedNode.ToString()) + "')";



请检查所提供的语法..请注意单引号和多个..始终确保关闭数据读取器(如果有)..



please check the syntax you have give.. be careful about the singe quote and multiple .. always make sure to close the data reader if any..


错误是什么..?您能给我错误的详细信息吗?
what is the error..? Can you give me the error details?


对象引用未设置为对象的实例(这是错误)
Object reference not set to an instance of an object(this is the error)


这篇关于我在此代码中有错误,紧急的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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