0

here is my code

SqlCommand insert_user = new SqlCommand("insert into dbo.users (username,password,firstname,lastname,address,country,city,phonenumber,gender,email) VALUES (' bader','123','beno','venp','33','pal','d',''1234','male'," + @TextBox3.Text + ");", badersql);

what i am trying is to insert from textbox3.text to my sql email column , the problem is when i try that , this error msg during debuging popups " Error 9 The name 'TextBox3' does not exist in the current context".

i tried '" + TextBox3.text + "' with @ and without , same problem

if it helps , here is all my code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data.Sql;

public partial class Default4 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {


        SqlConnection badersql = new SqlConnection("Data Source=BADER-VAIO\\SQLEXPRESS;Initial Catalog=webage;Persist Security Info=True;User ID=sa;Password=123");

        badersql.Open();
        SqlCommand insert_user = new SqlCommand("insert into dbo.users (username,password,firstname,lastname,address,country,city,phonenumber,gender,email) VALUES (' bader','123','beno','venp','33','pal','d',''1234','male'," + @TextBox3.Text + ");", badersql);

        insert_user.ExecuteNonQuery();
        //insert into webpage.dbo.users (username,password,firstname,lastname,address,country,city,phonenumber,gender,email) VALUES (' bader','123','beno','venp','33','pal','d',''1234','male','[email protected]');
        badersql.Close();


    }


    protected void RadioButton1_CheckedChanged(object sender, EventArgs e)
    {


    }
}

any suggestions ?

regards,

3 Answers 3

2

You don't have a server side control with the ID TextBox3 on your .aspx page. Did you rename it or remove it?

As an aside - this is wide open to SQL Injection attacks - you should be using parameterized queries instead of string concatenation.

Sign up to request clarification or add additional context in comments.

8 Comments

<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox> i have it
@Bader - have you rebuilt your solution?
i am sorry i am not familiar with sql injection attacks or else i am totally noob , if u just help me with the textbox part , that will be appreciated.
@Bader - I think that explaining huge security holes should be part of explaining things, especially to a noob.
yea i know , but asp.net in general is not on my interests , i am just trying to build a small local project on computer for education reasons , so if u can help , i will be thankful
|
0

Is that a typo in your question or in your code? ''1234' ?

Comments

0

it works , i was trying to debug the .cs page itself , thats why the erorr pop ups , thanks everyone for your help

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.