如何在Windows窗体中检索SQL Server数据库中的XML列数据 [英] How to retrive XML column data which is in SQL server database in windows form

查看:83
本文介绍了如何在Windows窗体中检索SQL Server数据库中的XML列数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有存储过程,其中包含5个字段ID,名称,地址,编号和详细信息。

详细信息是XML列,我需要以xml格式保存和检索窗口形式的xml列数据format.I已经将数据保存到数据库中,我停止了以xml格式检索这些数据。



如何以窗口形式获取它..

任何建议请..

谢谢。



我尝试过的事情:



  ALTER  程序 [dbo]。[pe_insert] 

@ id int
@ name nvarchar 50 ),
@ addres nvarchar 50 ),
@ number nvarchar 50
- @ details xml


AS
BEGIN
如果 @ id = 0
BEGIN
插入 进入人(姓名,地址,编号,详细信息) @ name @ addres @ number ' < root> < name>' + @ name + ' < address>' + @ addres + < span class =code-string>' < / address>
< number>'
+ @ number + ' '
END

else
BEGIN
更新 SET
name = < span class =code-sdkkeyword> @ name ,addres = @ addres ,number = @ number,details = ' < root>< name>' + @ name + ' < address>' + @ addres + ' < / address>
< number>'
+ @ number + ' ' 其中 id = @ id
END
END



GO



AND这是我的窗体表格代码...

<前lang =c#> 公开 Form1()
{
InitializeComponent();
}


私人 void Save_Click(< span class =code-keyword> object sender,EventArgs e)
{
SqlConnection con = new SqlConnection( @ Data Source = IBM163-PC0DE460; Initial Catalog = people data; Integrated Security = True);
con.Open();
SqlCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = pe_insert;

cmd.Parameters.AddWithValue( @ id,textBox1.Text );
cmd.Parameters.AddWithValue( @ name,textBox2.Text);
cmd.Parameters.AddWithValue( @ addres,textBox3.Text);
cmd.Parameters.AddWithValue( @ number,textBox4.Text);
con.Open();
cmd.ExecuteNonQuery();

con.Close();
MessageBox.Show( 成功保存);


}

解决方案

从您上面的评论中您似乎希望我们编写代码为了从表中检索任何数据。很遗憾,我们不是为您编写代码的业务。



这是MSDN文档的链接,解释了如何做您想做的事情:如何:执行返回行的存储过程 [ ^ ]



阅读文章试试看,如果你遇到问题,请务必回过头来解决具体问题


i have stored procedure which have 5 field id ,name,address,number and details.
details is the XML column and i need to save and retrieve that xml column data in window form in xml format.I have done with save data into database and i got stopped in retrieve those data in xml format.

How can i get it in window form ..
any suggestion please..
thank you.

What I have tried:

ALTER PROCEDURE [dbo].[pe_insert]
(
@id int,
@name nvarchar(50),
@addres nvarchar(50),
@number nvarchar(50)
--@details xml
)

  AS
BEGIN
If @id=0
BEGIN
insert into people(name,addres,number,details) values(@name,  @addres,  @number , '<root><name>'+@name+'<address>'+@addres+'</address>
                                                      <number>'+@number+'')
END

else 
BEGIN
 UPDATE people SET
     name =  @name, addres = @addres, number =@number, details = '<root><name>'+@name+'<address>'+@addres+'</address>
	                                                              <number>'+@number+''  where id=@id
END
END



GO


AND this is my window form code ...

public Form1()
        {
            InitializeComponent();
        }
            

        private void Save_Click(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection(@"Data Source=IBM163-PC0DE460;Initial Catalog=people data;Integrated Security=True");
            con.Open();
            SqlCommand cmd = con.CreateCommand();
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "pe_insert";
           
            cmd.Parameters.AddWithValue("@id", textBox1.Text);
            cmd.Parameters.AddWithValue("@name", textBox2.Text);
            cmd.Parameters.AddWithValue("@addres", textBox3.Text);
            cmd.Parameters.AddWithValue("@number", textBox4.Text);
            con.Open();
            cmd.ExecuteNonQuery();
            
            con.Close();
            MessageBox.Show("succesfully saved");
           

        }

解决方案

From your comments above you appear to want us to write the code for you to retrieve any data from your table. Unfortunately we are not in the business of writing code for you.

Here is a link to MSDN documentation that explains how to do what you want to do: How to: Execute a Stored Procedure that Returns Rows[^]

Read the article, give it a try and by all means come back with a specific question if you get stuck


这篇关于如何在Windows窗体中检索SQL Server数据库中的XML列数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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