0

hello all,
I need assistance on MS Access 2007 database with C#, I have a form with many textboxes.. and i need to store these userfilled data to my database! and after that I need to see detail of any perticular item form database!!! please say how to do this...

3
Contributors
12
Replies
13
Views
6 Years
Discussion Span
Last Post by finito
Featured Replies
  • 1
    sknake 1,622   6 Years Ago

    [QUOTE=finito;1220962]Well The Insert Statement in SQL would look like Insert INTO TABLE1 (FIRST_NAME) VALUES ('" + textbox2.text + "') did you connect your database and fill your dataset?[/QUOTE] You should always use parameterized queries. An example of parameters with OleDb: [code] private void buttonUpload_Click(object sender, EventArgs e) { using (OleDbConnection … Read More

0

bausahab what you are asking for is the main functionality.

Hmm Can you show what you have done so far?

0

just created a Form with textboxes and a access database.. and created query.
now want to save Form data to data base.. please give an illustrative coding for this problem..

0

oops! I connected database to my project already..and " conn.open();" just need how to add data in database with Form's textboxes.? for the present I am seeing your given links..and thanks for being online

Edited by bausahab: n/a

0

well .. I have one .. what code shoul I write for the inserting data into database.?
while I am adding string into " textbox2.text" and wnat to save it to database's TABLE 1> FIRST_NAME.. is it someting clear?:S

0

Well The Insert Statement in SQL would look like

Insert INTO TABLE1 (FIRST_NAME) VALUES ('" + textbox2.text + "')

did you connect your database and fill your dataset?

1

Well The Insert Statement in SQL would look like

Insert INTO TABLE1 (FIRST_NAME) VALUES ('" + textbox2.text + "')

did you connect your database and fill your dataset?

You should always use parameterized queries. An example of parameters with OleDb:

private void buttonUpload_Click(object sender, EventArgs e)
    {
      using (OleDbConnection conn = new OleDbConnection(connStr))
      {
        conn.Open();
        using (OleDbCommand cmd = new OleDbCommand("Insert Into IMG (IMG) Values (?)", conn))
        {
          cmd.Parameters.Add(new OleDbParameter("@IMG", OleDbType.Binary)).Value = System.IO.File.ReadAllBytes(@"C:\picture2.bmp");
          cmd.ExecuteNonQuery();
        }
        conn.Close();
      }
    }

It is very similar when using ODBC or SQL data access objects as well.

0

I have many textboxes for to submit details of a student and I need to add these details to database(MS access).. how can I do this .. can you Please write any illustrative code for this task?? I maked database as equal fields in my form's textboxes are.... and connect this database to my project.. with adapter and dataset.. now the INSERing data is remaining.. Please solve.

0

Like Sknake said

using (OleDbCommand cmd = new OleDbCommand("Insert Into IMG (IMG) Values (?)", conn))

now Just Add a comma

public static OleDbDataAdapter CreateCustomerAdapter(OleDbConnection conn)
{
  OleDbDataAdapter da = new OleDbDataAdapter();
  OleDbCommand cmd;

  // Create the SelectCommand.

  cmd = new OleDbCommand("SELECT * FROM Customers " +
                       "WHERE Country = @Country AND City = @City", conn);

  cmd.Parameters.Add("@Country", OleDbType.VarChar, 15);
  cmd.Parameters.Add("@City", OleDbType.VarChar, 15);

  da.SelectCommand = cmd;

  // Create the InsertCommand.

  cmd = new OleDbCommand("INSERT INTO Customers (CustomerID, CompanyName) " +
                       "VALUES (@CustomerID, @CompanyName)", conn);

  cmd.Parameters.Add("@CustomerID", OleDbType.Char, 5, "CustomerID"); // Here "CustomerID" would be textBox1.text
  cmd.Parameters.Add("@CompanyName", OleDbType.VarChar, 40, "CompanyName"); //Here "CustomerName" would be textBox2.text and so on

  da.InsertCommand = cmd;

  return da;

http://msdn.microsoft.com/en-us/library/system.data.oledb.oledbdataadapter.insertcommand%28VS.71%29.aspx

Edited by finito: n/a

This question has already been answered. 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.