Inserting a command into a database
- From: "Lars" <jon.doe@xxxxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 03 Mar 2008 20:15:24 GMT
Hi
I have the following method. HOw do I performe the task to the table in the
database?
protected void FormView1_PageIndexChanging(object sender,
FormViewPageEventArgs e)
{
Button S = sender as Button;
if (S != null)
{
TextBox Name = (TextBox) S.Parent.FindControl("tbName");
TextBox Company = (TextBox) S.Parent.FindControl("tbCompany");
TextBox Email = (TextBox) S.Parent.FindControl("tbEmail");
TextBox Subject = (TextBox) S.Parent.FindControl("tbSubject");
TextBox Message = (TextBox) S.Parent.FindControl("tbMessage");
Label ID = (Label) S.Parent.FindControl("lblID");
SqlDataSource DS = (SqlDataSource)
S.Parent.FindControl("SqlDataSource1");
SqlDataSource1.InsertCommand = "insert into Emails (ID, Name,
Company, Subject, Message ) values ( @ID, @Name, @Company, @Subject,
@Message );";
if ((Name != null) && (Company != null) && (Email != null) &&
(Subject != null) && (Message != null) && (ID != null) &&
(DS != null) )
{
SqlDataSource1.InsertParameters["ID"].DefaultValue = ID.Text
+ 1;
SqlDataSource1.InsertParameters["Name"].DefaultValue =
Name.Text;
SqlDataSource1.InsertParameters["Company"].DefaultValue =
Company.Text;
SqlDataSource1.InsertParameters["Email"].DefaultValue =
Email.Text;
SqlDataSource1.InsertParameters["Subject"].DefaultValue =
Subject.Text;
SqlDataSource1.InsertParameters["Message"].DefaultValue =
Message.Text;
}
SqlDataSource1.
}
}
.
- Follow-Ups:
- Re: Inserting a command into a database
- From: Phil H
- Re: Inserting a command into a database
- Prev by Date: Re: localiztion app_localresources ie6 vs ie7
- Next by Date: Re: Regex help
- Previous by thread: Prerender and Gridview - Object reference not set to an instance of an object.
- Next by thread: Re: Inserting a command into a database
- Index(es):
Loading