Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 2011

    Unanswered: how to insert and retrieve data from .mdf file

    i want to use sql server as a back end for my shopping cart using have created an "news.mdf" under app_data folder of my website in visual studio2010...but i tried to connect it to database using below command
    ..but showing error...
    sqlconnectionstring = "Data Source=.\SQLEXPRESS;attachdbfilename=\App_Data\myd atabase_data.mdf;Integrated Security=true;User Instance=true"
    myconnection.ConnectionString = sqlconnectionstring

    insertstring = "insert into News_table values(@N_head,@n_contents); "
    mycommand = New SqlCommand(insertstring, myconnection)
    mycommand.Parameters.Add(New SqlParameter("@N_head", SqlDbType.NVarChar, 1000))
    mycommand.Parameters("@N_head").Value = nh_t.Text
    mycommand.Parameters.Add(New SqlParameter("@n_contents", SqlDbType.Text, 4000))
    mycommand.Parameters("@n_contents").Value = nc_ta.Value

    MsgBox("news added successfully")

    Catch ex As Exception
    MsgBox("insertion failed")
    End Try

    please guide me to fix this error..and how to display this data in my site also

  2. #2
    Join Date
    Nov 2011
    Can you post the error message?

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts