Click here to Skip to main content
15,885,704 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I am using detailsView in my website. I am using oracle 10g. OleDB Connection.

My Code is:
HTML
<asp:detailsview id="DetailsView1" runat="server" allowpaging="True" xmlns:asp="#unknown">
        AutoGenerateDeleteButton="True" AutoGenerateEditButton="True" 
        AutoGenerateInsertButton="True" AutoGenerateRows="False" DataKeyNames="SRNO" 
        DataSourceID="SqlDataSource1" Height="50px" Width="680px" 
        BackColor="White" BorderColor="#CC9966" BorderStyle="None" BorderWidth="1px" 
        CellPadding="4"&gt;
        <footerstyle backcolor="#FFFFCC" forecolor="#330099" />
        <rowstyle backcolor="White" forecolor="#330099" />
        <pagerstyle backcolor="#FFFFCC" forecolor="#330099" horizontalalign="Center" />
        <fields>
            <asp:templatefield headertext="SRNO" sortexpression="SRNO">
                <edititemtemplate>
                    <asp:label id="Label1" runat="server" text="&lt;%# Eval("SRNO") %&gt;"></asp:label>
                </edititemtemplate>
                <insertitemtemplate>
                    <asp:textbox id="TextBox2" runat="server" readonly="True"></asp:textbox>
                </insertitemtemplate>
                <itemtemplate>
                    <asp:label id="Label2" runat="server" text="&lt;%# Bind("SRNO") %&gt;"></asp:label>
                </itemtemplate>
            </asp:templatefield>
            <asp:templatefield headertext="CERTPURPOSE" sortexpression="CERTPURPOSE">
                <edititemtemplate>
                    <asp:textbox id="TextBox1" runat="server" text="&lt;%# Bind("CERTPURPOSE") %&gt;">
                        TextMode="MultiLine" Width="350px" Height="66px"&gt;</asp:textbox>
                </edititemtemplate>
                <insertitemtemplate>
                    <asp:textbox id="TextBox1" runat="server" text="&lt;%# Bind("CERTPURPOSE") %&gt;">
                        Height="66px" TextMode="MultiLine" Width="350px"&gt;</asp:textbox>
                </insertitemtemplate>
                <itemtemplate>
                    <asp:label id="Label1" runat="server" text="&lt;%# Bind("CERTPURPOSE") %&gt;"></asp:label>
                </itemtemplate>
            </asp:templatefield>
        </fields>
        <headerstyle backcolor="#990000" font-bold="True" forecolor="#FFFFCC" />
        <editrowstyle backcolor="#FFCC66" font-bold="True" forecolor="#663399" />
    </asp:detailsview>
    <asp:sqldatasource id="SqlDataSource1" runat="server" xmlns:asp="#unknown">
        ConnectionString="&lt;%$ ConnectionStrings:ConnectionString1 %&gt;" 
        DeleteCommand="DELETE FROM PURPOSE_MASTER" 
        InsertCommand="INSERT INTO PURPOSE_MASTER(SRNO, CERTPURPOSE, EX1, EX2) VALUES (0,' <b>// HERE i want to point Specific Field to insert into Database</b> ', 0, '--')" 
        ProviderName="&lt;%$ ConnectionStrings:ConnectionString1.ProviderName %&gt;" 
        SelectCommand="SELECT SRNO, CERTPURPOSE FROM PURPOSE_MASTER" 
        UpdateCommand="UPDATE PURPOSE_MASTER SET SRNO =, CERTPURPOSE = ''"&gt;
    </asp:sqldatasource>

I have created these statement manually. These all are Databounds.
Actually Square bracket raises error in Oracle Query.

Now I want to point specific textBox while inserting in database.
I have used ' @ ' symbol, but it raises runtime Error.

Please Help!
Posted
Updated 2-Jun-10 7:03am
v2

1 solution

There are several ways to do this. One way is to use code-behind in the SqlDataSource1_Inserting event. In the event code you can set the SqlDataSource1.InsertCommand property string to whatever you need. Something like this might do it.


protected void SqlDataSource1_Inserting(object sender, ObjectDataSourceMethodEventArgs e)
{
  TextBox myTextbox = (TextBox)DetailsView1.FindControl("TextBox1");
  string MySQL = ="INSERT INTO PURPOSE_MASTER(SRNO, CERTPURPOSE, EX1, EX2) VALUES (0,'"
  MySQL += myTextbox.Text;
  MySQL += "', 0, '--')";
  SqlDataSource1.InsertCommand = MySQL;
}
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900