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

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

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

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.

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();
        }
      }
    }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.