Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

INSERT statement via Microsoft Expression Web

Status
Not open for further replies.

Aluminum

Programmer
Jun 8, 2007
41
US
I have a SQL database hosted through network solutions. I am designing a web site in expression web (next version of frontpage). I can make a form to SELECT data from the SQL database.

I cannot find an example or a starting point to INSERT into my table.


I simply want to INSERT a new record into Tbl_Example. For example, Joe Doe in the Name field via a form after clicking a submit button. Can someone give me a starting point please?

Thanks in advance!

 
did you use a helper/wizard to get the select setup or did you do it by hand in the codebehind equivalent?

-The answer to your problem may not be the answer to your question.
 
I used the helper to form the select statement. The helper allowed me to set up the connection string. It appears the helper will only allow me to connect to an Access DB for an insert. I cannot find anywhere to do an insert using text boxes for fields and a submit button. I think I have to insert my own code. Do you know of any good sites with an example of this methodology?
 
What sort of database are you using to store your data?

Here is how to get the connection string. from your .config file. It may need to be modified slightly, i believe Expression uses .Net 3.0
Code:
    Public Shared Function GetConnectionString(ByVal strConnection As String) As String
        Dim strReturn As New String("")
        If Not String.IsNullOrEmpty(strConnection) Then
                strReturn = ConfigurationManager.ConnectionStrings(strConnection).ConnectionString
        Else
            strReturn = ConfigurationManager.ConnectionStrings("My_Conn").ConnectionString
        End If
        Return strReturn
    End Function

Here an example of an insert, that uses a stored procedure. If you are going to do "in-line" SQL you would just take the guts of you procedure and place it where i have "MY_Proc_name" and then remove the line that says .commandType = StoredProcedure

Code:
        Dim cnMyConn As New SqlConnection(myHelpers.GetConnectionString(""))
        Dim cmdGetStuff As New SqlCommand("dbo.MY_Proc_name", cnMyConn)
        cmdGetStuff.CommandType = CommandType.StoredProcedure
        cmdGetStuff .Parameters.Add("@param1", SqlDbType.Char).Value = TextBox1.text
        cnSP.Open()
        intSuccess = cmdGetStuff.ExecuteScalar

-The answer to your problem may not be the answer to your question.
 
I am using a SQL database. The above solution does not work. I can retrieve data as follows:

=============== start code =======================
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<html xmlns="
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>BrowseProfiles</title>
</head>

<body>

<form id="form1" runat="server">
<asp:GridView runat="server" id="GridView1" AutoGenerateColumns="False" DataSourceID="SqlDataSource1">
<Columns>
<asp:boundfield DataField="email" SortExpression="email" HeaderText="email">
</asp:boundfield>
<asp:boundfield DataField="City" SortExpression="City" HeaderText="City">
</asp:boundfield>
<asp:boundfield DataField="usState" SortExpression="usState" HeaderText="usState">
</asp:boundfield>
<asp:boundfield DataField="Country" SortExpression="Country" HeaderText="Country">
</asp:boundfield>
<asp:boundfield DataField="phone" SortExpression="phone" HeaderText="phone">
</asp:boundfield>
<asp:boundfield DataField="languages" SortExpression="languages" HeaderText="languages">
</asp:boundfield>
<asp:boundfield DataField="nickname" SortExpression="nickname" HeaderText="nickname">
</asp:boundfield>
<asp:boundfield DataField="age" SortExpression="age" HeaderText="age">
</asp:boundfield>
<asp:boundfield DataField="sex" SortExpression="sex" HeaderText="sex">
</asp:boundfield>
<asp:boundfield DataField="heightfeet" SortExpression="heightfeet" HeaderText="heightfeet">
</asp:boundfield>
<asp:boundfield DataField="heightinches" SortExpression="heightinches" HeaderText="heightinches">
</asp:boundfield>
<asp:boundfield DataField="weight" SortExpression="weight" HeaderText="weight">
</asp:boundfield>
<asp:boundfield DataField="eyecolor" SortExpression="eyecolor" HeaderText="eyecolor">
</asp:boundfield>
<asp:boundfield DataField="haircolor" SortExpression="haircolor" HeaderText="haircolor">
</asp:boundfield>
<asp:boundfield DataField="interests" SortExpression="interests" HeaderText="interests">
</asp:boundfield>
<asp:boundfield DataField="status" SortExpression="status" HeaderText="status">
</asp:boundfield>
<asp:boundfield DataField="address" SortExpression="address" HeaderText="address">
</asp:boundfield>
<asp:boundfield DataField="AdditionalInformation" SortExpression="AdditionalInformation" HeaderText="AdditionalInformation">
</asp:boundfield>
</Columns>
</asp:GridView>
</asp:SqlDataSource>
</form>

</body>

</html>

=============== STOP code =======================

I cannot seem to process an INSERT statement. I have searched online for an example with no luck.
 
where is your code behind file?

-The answer to your problem may not be the answer to your question.
 
I don't know. That is the code I cut from expression web code window.
 
if you don't know where it is then you probably haven't written any code for it, which almost makes it moot.

You should have some form of Datasource object on your webpage design, probably at the bottom. You should be able to access it and set it up for an insert as well as a select.

-The answer to your problem may not be the answer to your question.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top