5
Contributors
4
Replies
5
Views
8 Years
Discussion Span
Last Post by sknake
0

how to add datas from a web page to a data base using C# in asp.net
(a symple mathod)

Hi ChatuD,

Can you explain more? What are you using to get the data from the web page (DropDownList, CheckBox, TextBox, GridView, etc).? Give us more details about the context so we can give you more accurate suggestions. =)

Thanks,

Ana

0

you can open an sql connection and then use "Insert" commands to add it to database

0

If you want to be a good programmer one day, you need to read and practice and make research before you can ask someone. It seems that you did not even try , nor Google. the First thing you can do is to buy a book and read , this is a very basic question and it has been covered by almost all beginners book.

0

Here is an example of inserting an image from the hard drive. Obviously you want to change the input from a file to the controls you have on a page:

private static string BuildSqlNativeConnStr(string server, string database)
    {
      return string.Format("Data Source={0};Initial Catalog={1};Integrated Security=True;", server, database);
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
      byte[] bytes = File.ReadAllBytes(@"C:\picture.bmp");
      const string query = @"Insert Into Picture (Picture) Values (@Picture)";
      using (SqlConnection conn = new SqlConnection(BuildSqlNativeConnStr("apex2006sql", "Bugs")))
      {
        conn.Open();
        using (SqlCommand cmd = new SqlCommand(query, conn))
        {
          SqlParameter parm = new SqlParameter("@Picture", SqlDbType.Image);
          parm.Value = bytes;
          cmd.Parameters.Add(parm);
          cmd.ExecuteNonQuery();
        }
      }
    }
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.