inserting values using a asp.net form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • teresamakamu
    New Member
    • Oct 2011
    • 5

    inserting values using a asp.net form

    Hi.
    I want to insert data to sybase using an HTML form in asp.net.

    I have the following code:
    Code:
    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Data.SqlClient;
    using Sybase.Data.AseClient;
    
    public partial class test : System.Web.UI.Page
    {
    
        
        private AseConnection TempDMT_conn = new AseConnection(ConfigurationSettings.AppSettings["connectionString"]);
       
        protected void Page_Load(object sender, EventArgs e)
        {
    
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
    
    
            string username = txtusername.Text;
            string password = txtpassword.Text;
    
                TempDMT_conn.Open ();
    
    
                AseDataAdapter adapter = new AseDataAdapter();
                adapter.MissingMappingAction = MissingMappingAction.Passthrough;
                adapter.MissingSchemaAction = MissingSchemaAction.Add;
                adapter.SelectCommand = new AseCommand("Select * from login", TempDMT_conn);
                adapter.InsertCommand = new AseCommand("INSERT INTO login(username,password)" + "VALUES(@username,@password)", TempDMT_conn);
                adapter.InsertCommand.UpdatedRowSource = UpdateRowSource.None;
                AseParameter parm = new AseParameter("@username", AseDbType.VarChar, 10);
                parm.SourceColumn = "username";
                parm.SourceVersion = DataRowVersion.Current;
                adapter.InsertCommand.Parameters.Add(parm);
                parm = new AseParameter("@password", AseDbType.VarChar, 10);
                parm.SourceColumn = "password";
                parm.SourceVersion = DataRowVersion.Current;
                adapter.InsertCommand.Parameters.Add(parm);
    
                DataTable dataTable = new DataTable("login");
    
                int rowCount = adapter.Fill(dataTable);
                DataRow row1 = dataTable.NewRow();
                row1[0] = "teresama";
                row1[1] = "terry";
                dataTable.Rows.Add(row1);
                int recordsAffected = adapter.Update(dataTable);
    
                dataTable.Clear();
                rowCount = adapter.Fill(dataTable);
    
                TempDMT_conn.Close();
           
    
                
        }
    }
    This does connect to sybase but now I want to get values from TextBox and insert it to sybase.

    Could anyone help?
    Last edited by Frinavale; Oct 28 '11, 01:44 PM. Reason: Added code tags and fixed grammar and spelling errors. Please post code in code tags and use proper English.
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    If you have a TextBox on your asp.net Page you should be able to just access it's Text property to retrieve the text.

    Unless your TextBox is part of another control (like a GridView for example). In this case, you first need to retrieve the TextBox from the control and then access it's Text property.

    Comment

    Working...