下面我给了代码 [英] below i gave the code

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

问题描述

我必须将节点存储在sql数据库中tablename是父级plzzzzzzz可以向我发送任何代码



i have to store nodes in sql database tablename is parent plzzzzzzz can any one snd me code



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
    {

        SqlConnection con = new SqlConnection("server=192.168.0.50\\CIODEVDB;user id=sa;password=epm@3108;database=parent");
        SqlCommand cmd = new SqlCommand();
        SqlDataAdapter da;
        DataSet ds;
        SqlCommandBuilder bldr;
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void btnadd_Click(object sender, EventArgs e)
        {
            da = new SqlDataAdapter("select *from details", con);
            ds = new DataSet();
            da.Fill(ds, "x");
            da.FillSchema(ds, SchemaType.Source, "x");
            bldr = new SqlCommandBuilder(da);

            con.Open();

            treeView1.Nodes.Add("");
            string yourParentNode;
            yourParentNode = textBox1.Text.Trim();
            treeView1.Nodes.Add(yourParentNode);
            treeView1.EndUpdate();

            TreeNode node;

            node = treeView1.Nodes.Add("");
            node.Nodes.Add("");
            con.Close();
        }

        private void btnparent_Click(object sender, EventArgs e)
        {
            TreeNode node;
           node = treeView1.Nodes.Add("");

           node.Nodes.Add("");
           string yourParentNode;
            yourParentNode = textBox1.Text.Trim();
            treeView1.Nodes.Add(yourParentNode);
            treeView1.EndUpdate();
        }

        private void btnremove_Click(object sender, EventArgs e)
        {
            treeView1.Nodes.Remove(treeView1.SelectedNode);
            //// Clears all nodes.
            //treeView1.Nodes.Clear();

        }
        
    }
}



[edit]添加了代码块-OriginalGriff [/edit]



[edit]Code block added - OriginalGriff[/edit]

推荐答案

您只需要使用INSERT Sql命令即可:
You just need to use the INSERT Sql Command:
INSERT INTO MyTable (Column1, Column2) VALUES ('Value1', 'value', ...)


根据偏好,使用参数化查询:


By preference, use a Parametrized query:

using (SqlConnection con = new SqlConnection(strConnect))
    {
    con.Open();
    using (SqlCommand com = new SqlCommand("INSERT INTO myTable (myColumn1, myColumn2) VALUES (@C1, @C2)", con))
        {
        com.Parameters.AddWithValue("@C1", myValueForColumn1);
        com.Parameters.AddWithValue("@C2", myValueForColumn2);
        com.ExecuteNonQuery();
        }
    }


这篇关于下面我给了代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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