Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:

SQL
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 ...
C#
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");
           

        }
Posted
Updated 9-Mar-17 4:39am
v2
Comments
CHill60 9-Mar-17 10:22am    
What is your actual problem?
Member 12927094 9-Mar-17 10:26am    
i want to retrieve the XML column data in windows form...
thankyou
CHill60 9-Mar-17 10:29am    
The code you have shared is what you are using to update the database. You need to share the code that you have so far for extracting the information from the database - use the Improve question link. That way we might be able to help you with the specific problem
Member 12927094 9-Mar-17 10:33am    
In question i mention i need to save and retrieve the data in window form. for above code what i have mention is for save data into database. now i need to retrieve those data in window form.
how can i retrieve that data ?
CHill60 9-Mar-17 10:35am    
Your question implied that it was only the XML column that you could not retrieve. Now you seem to be asking us to write all of the code for you to get information from the database - that's not how this forum works

1 solution

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
 
Share this answer
 
Comments
Member 12927094 9-Mar-17 10:42am    
thank you...i think it will help me.
CHill60 9-Mar-17 10:45am    
It is quite a good article. Don't forget - if you do get stuck then do come back and ask another question. It might be best to raise a new question if you do though. Best of luck.
Member 12927094 9-Mar-17 10:59am    
yup..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900