Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read SiteMap

Tags: , , , , , , ,

Sponsored Links


Is it possible to insert value of TextBox into Sql database using C sharp?

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 05-01-2010
Member
 
Join Date: Dec 2009
Posts: 41
Is it possible to insert value of TextBox into Sql database using C sharp?

Sponsored Links
Hi Friends,

Is it possible to insert value of TextBox into Sql database using C sharp ? I am trying to code the c sharp program to insert value of TextBox into Sql database, but I am not yet successful in it.
I want to know your suggestion over this, please don't hesitate to suggest. I am waiting for your reply.

Reply With Quote
  #2  
Old 05-01-2010
opaper's Avatar
Member
 
Join Date: May 2008
Posts: 2,371
Re: Is it possible to insert value of TextBox into Sql database using C sharp?

Hi,

Use following statement in your program to insert the textbox value and execute that program.
Quote:
sqlcommand SQcmd =
new sqlcommand ("INSERT INTO TABdemo values (@textboxName1.text, @textboxName2.text)", Connectionstring);
I hope it will definitely help you.
Reply With Quote
  #3  
Old 05-01-2010
MindSpace's Avatar
Member
 
Join Date: Feb 2008
Posts: 1,839
Re: Is it possible to insert value of TextBox into Sql database using C sharp?

Hello Friend,

Yes it is possible to insert value of TextBox into Sql database using C sharp. I have tried this try of program many times. But code for this program is quit complicated to understand, See below:
Quote:
SqlCommand CmdSqlStr = new SqlCommand("insert into Customers (FirstNm,SurNm,Addr,,Pstcode,PhoneNum)
Values (@FirstNm,@SurNm,@Addr,@Pstcode,@PhoneNum)", conn);

conn.Open();

CmdSql.Parameters.AddWithValue("@PhoneNum", PhoneNum);
CmdSql.Parameters.AddWithValue("@Pstcode", Pstcode);
CmdSql.Parameters.AddWithValue("@FirstNm", FirstNm);
CmdSql.Parameters.AddWithValue("@SurNm", SurNm);
CmdSql.Parameters.AddWithValue("@Addr", Addre);

CmdSql.ExecuteNonQuery();

conn.close();
Reply With Quote
  #4  
Old 05-01-2010
Modifier's Avatar
Member
 
Join Date: Jan 2008
Posts: 1,507
Re: Is it possible to insert value of TextBox into Sql database using C sharp?

Hi,

I think you need to use the "insert" command of SQL in your C sharp program. First define the connection string for SQL database connection. Then you need to assign the "insert" command to the defined connection string. Following is the syntax and example for the same:

Quote:
Syntax:
Insert into tableName(columnName, columnName,columName) values (ColumnValues,ColumnValues,ColumnValues)

Example:
Insert into emply (EmpName, empl_id, dsigntion) values ('"+txtbox1.text+"',"+txtbox2.text+",'"+textbox3.text +"');
Reply With Quote
  #5  
Old 05-01-2010
Praetor's Avatar
Member
 
Join Date: Apr 2008
Posts: 1,943
Re: Is it possible to insert value of TextBox into Sql database using C sharp?

Example of inserting textbox value into the sql:
Quote:
void Buttn1_Click(EventArgs e, object sender )
{

SqlConnection myCon = new SqlConnection();

myCon.ConnectionString = “Put connection string here“;

myCon.Open();

string strqr = “Insert into stud values (” + TextBoxOne.Text +
“,’” + TextBoxTwo.Text + “‘,’” + TextBoxThree.Text + “‘)”;

SqlCommand myCm = new SqlCommand (strqr, myCon);

int numrw = myCm.ExecuteNonQuery();

myCon.Close();

}
Reply With Quote
  #6  
Old 05-01-2010
Member
 
Join Date: May 2008
Posts: 2,000
Re: Is it possible to insert value of TextBox into Sql database using C sharp?

I have used below sqlcommand statement in my c sharp program for sql database connection. Copy this sqlcommand statement and replace the the values of "txtbx1" and "txtbx2" with your defined names for text boxes:
Quote:
sqlcommand cmmd =
new sqlcommand("insert into addressdemo values
('"+ txtbx1.text +"', "+ txtbx2.text +")",
connectionstring);
Reply With Quote
Reply

  TechArena Community > Software > Software Development


Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Is it possible to insert value of TextBox into Sql database using C sharp?"
Thread Thread Starter Forum Replies Last Post
insert into select statement for database Aidan 12 Software Development 5 09-03-2010 09:08 PM
Insert DataGridview into database Neil'o Software Development 3 24-09-2009 11:28 AM
How do I create a textbox in vb that lets you insert tabs? Chandrakant81 Software Development 3 26-02-2009 08:59 PM
How can I bind textbox with column in SQL database? SushmitaP Software Development 3 19-02-2009 09:57 PM
Insert image in access database from vb 6.0 Vireshh Software Development 2 22-01-2009 08:06 PM


All times are GMT +5.5. The time now is 04:50 AM.