hi..

Here i can simply explain to store xml data into sql database ,

create a SQL database like this...
1)carsid           varchar(50)
2)carsmodel     varchar(50)
3)carscolor       varchar(50)

This is a xml file to store into sql table..

- <system>
- <message>
  <Carsid>1</Carsid>
  <Carsmodel>Toyota</Carsmodel>
  <Carscolor>Green</Carscolor>
  </message>
- <message>
  <Carsid>2</Carsid>
  <Carsmodel>Kia</Carsmodel>
  <Carscolor>Yellow</Carscolor>
  </message>
- <message>
  <Carsid>3</Carsid>
  <Carsmodel>swift</Carsmodel>
  <Carscolor>silver</Carscolor>
  </message>
  </system>

Then enter the code behind submit button to store xml data into sql databse..

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
       
Dim Carsid, Carsmodel, Carscolor,str As String


 Dim sXMLFilePath As String = "C:\users\admin\desktop\12.xml"


        Dim document As New XmlDocument()
        document.Load(sXMLFilePath)




        Dim xmlNodeList As XmlNodeList = document.SelectNodes("system/message")
        For Each node As XmlNode In xmlNodeList
            Carsid = Integer.Parse(node("Carsid").InnerText)
            Carsmodel = node("Carsmodel").InnerText
            Carscolor = node("Carscolor").InnerText


            str = "INSERT INTO car (Carsid,Carsmodel,Carscolor) values ('" & Carsid & "', '" & Carsmodel & "','" & Carscolor & "')"
            sqlcmd = New SqlCommand(str, sqlcon)
                    sqlcmd.CommandType = CommandType.Text
                    sqlcmd.ExecuteNonQuery()
        Next




    End Sub

i hope this helpful to u.................




hi...

In previous articles we have seen about uploading files into folder..This articles to update a files into  database...
For that you have to add following items in design side..
1) File upload
2)1 Button
3) text box
4) Label


Before in SQL you have to create a table like this..
GO
CREATE TABLE [dbo].[upload](
[fileid] [int] IDENTITY(1,1) NOT NULL,
[ImageName] [varchar](max) COLLATE SQL_Latin1_General_CP1_CS_AS NULL,
[Image] [image] NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]


Follow the server side coding....
In submit button you have to add the following codes.....

In vb.net file uploading has one important property  HTTPPOSTEDFILE, by using this property we can easily get the file upload details
like file length,file content type and file name.....Also we can easily check  file extension..For an example if we want to upload only gif image
means by using content type we can check the file type...After checking we can upload the file into database


 Try
'Checking the file in fileupload
            If FileUpload1.HasFile Then


                Dim imageSize As Byte()
                imageSize = New Byte(FileUpload1.PostedFile.ContentLength - 1) {}




                Dim postfile As HttpPostedFile = FileUpload1.PostedFile()


                postfile.InputStream.Read(imageSize, 0, CInt(FileUpload1.PostedFile.ContentLength))


                ' Create SQL Connection 
                Dim con As New SqlConnection()
                con.ConnectionString = ConfigurationManager.ConnectionStrings("Con").ConnectionString


                ' Create SQL Command 
'Checking file type
                If postfile.ContentType.ToLower() = "image/gif" Then


                    Dim cmd As New SqlCommand()
                    cmd.CommandText = "INSERT INTO upload(ImageName,Image) VALUES (@ImageName,@Image)"
                    cmd.CommandType = CommandType.Text
                    cmd.Connection = con
                    Dim ImageName As New SqlParameter("@ImageName", SqlDbType.VarChar, 50)
                    ImageName.Value = TextBox1.Text.ToString
                    cmd.Parameters.Add(ImageName)


                    Dim imagelenth As New SqlParameter("@Image", SqlDbType.Image, imageSize.Length)
                    imagelenth.Value = imageSize
                    cmd.Parameters.Add(imagelenth)
                    con.Open()
                    Dim result As Integer = cmd.ExecuteNonQuery()
                    con.Close()
                Else
                    Label1.Text = "Its not a gif image"
                End If
            Else
                Label1.Text = "please select the file to uplaod"
            End If
        Catch ex As Exception
            Response.Write(ex.Message)
        End Try


    End Sub

Hope this helps to u.....

10:24 PM

Upload a File in ASP.NET using VB coding

Posted by vijay



hi..
In this article you are going to see about to upload file in asp.net

Folloe the client side coding......
DESIGN SIDE

Normally if you want to upload a file you have to add FILEUPLOAD its present in the toolbox

then you have to add one button rename it submit
Follow server side
SERVER SIDE:

In server side you have to add the following code in the submit button event ....

Protected Sub submit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles 

 Try

            Dim filetype As String
            Dim file As String
            Dim filepath As String
            Dim uploadpath As String
          
            file = FileUpload1.PostedFile.FileName

            filepath = Path.GetFileName(file)
            uploadpath = "d:\vijay\"

                FileUpload1.PostedFile.SaveAs(Path.Combine(uploadpath, file))
                Response.Write("upload succesfully")
           
            

        Catch ex As Exception
            Response.Write(ex.Message)


        End Try
End Sub

Normally when upload one issue araise ,How to check the upload file name extension..this one was the big problem for developer....
For checking extension in VB present one function i.e CONTENT TYPE....
By using this function you have check the file extension coding..

In this exanble i checked the gif image file ...


Try

            Dim filetype As String
            Dim file As String
            Dim filepath As String
            Dim uploadpath As String
            filetype = FileUpload1.PostedFile.ContentType
            file = FileUpload1.PostedFile.FileName

            filepath = Path.GetFileName(file)
            uploadpath = "d:\vijay\"
            If filetype = "image/gif" Then

                FileUpload1.PostedFile.SaveAs(Path.Combine(uploadpath, file))
                Response.Write("upload succesfully")
            Else
                Response.Write("its not gif file")
            End If

        Catch ex As Exception
            Response.Write(ex.Message)


        End Try
By using this method you can easily check file type at the time of upload.....

i hope this article helpful to uu.....

plz post your valuable comments here..............