Today's Posts Follow Us On Twitter! TFL Members on Twitter  
Forum search: Advanced Search  
Navigation
Marketplace
  Members Login:
Lost password?
  Forum Statistics:
Forum Members: 24,256
Total Threads: 81,169
Total Posts: 566,839
There are 59 users currently browsing (tf).
 
  Our Partners:
 
  TalkFreelance     Design and Development     Programming     .NET and MSSQL :

Inserting New DB Row With ASP.NET?

Thread title: Inserting New DB Row With ASP.NET?
Reply    
    Thread tools Search this thread Display Modes  
12-05-2008, 01:56 AM
#1
Steven Fergus is offline Steven Fergus
Status: Hey, I'm Steven
Join date: Feb 2007
Location:
Expertise:
Software:
 
Posts: 1,213
iTrader: 3 / 100%
 

Steven Fergus is on a distinguished road

  Old  Inserting New DB Row With ASP.NET?

Hiya,

I was wondering how you go about inserting new rows into a DB using ASP.NET?

Cheers,
Steven

Reply With Quote
12-10-2008, 09:50 AM
#2
freelancerguy is offline freelancerguy
Status: Junior Member
Join date: Dec 2008
Location:
Expertise:
Software:
 
Posts: 63
iTrader: 1 / 100%
 

freelancerguy is on a distinguished road

Send a message via AIM to freelancerguy Send a message via MSN to freelancerguy Send a message via Yahoo to freelancerguy Send a message via Skype™ to freelancerguy

  Old

SqlConnection sqlcon=new SqlConnection(Your SQL Connection String);
Sqlcon.Open();
SqlCommand sqlcmd=new SqlCommand(Your insert commant,SqlCon);
sqlcmd.ExecuteNonQuery
Sqlcon.Close()

Reply With Quote
12-15-2008, 12:01 AM
#3
garydevenay is offline garydevenay
Status: I'm new around here
Join date: Nov 2008
Location:
Expertise:
Software:
 
Posts: 11
iTrader: 0 / 0%
 

garydevenay is on a distinguished road

  Old

above is correct, but you may want to read up on constructing layers (data access layer / business logic layer) as you do not want everything to happen on your code behind.

Reply With Quote
05-30-2009, 03:15 AM
#4
lonelyrider is offline lonelyrider
Status: I'm new around here
Join date: May 2009
Location:
Expertise:
Software:
 
Posts: 18
iTrader: 0 / 0%
 

lonelyrider is on a distinguished road

  Old

Well theres two ways this can be done articture wise

Connected one has already been posted

Disconnected one

//i hope you know how a connection String is formed
SqlConnection con=new SqlConnection(connectionString);
//data set holds the schema
DataSet ds=new DataSet();
SqlDataAdapter da=new SqlDataAdapter("select * from db",con);
da.Fill("tablename");
//Command builder builds the command for you
SqlCommandBuilder cbd=new SqlCommandBuilder(da);
//data table holds a particular table
DataTable dt=ds.Tables["tablename"];

// add a new blank row
DataRow dr=dt.Rows.Add();
//start adding rows
dr[0]="Primary key";
dr[1]="name";
dr[2]=double.Parse(textBox1.Text);
//done? then commit the row
int rowAdded=da.Update("tablename");
Response.Write(rowAdded.ToString()+" no. of rows added");

Reply With Quote
Reply    


Thread Tools
Display Modes

  Posting Rules  
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump:
 
  Contains New Posts Forum Contains New Posts   Contains No New Posts Forum Contains No New Posts   A Closed Forum Forum is Closed