I'm working with ASP.NET and SQL Server and building the whole project in Visual Studio. If it's not clear I'm trying to update a users table with a randomly generated number where the users username is present then insert the date, usersid and orderid and userid into the `Orders` table. 

I can't see anything immediately wrong with this. I'm getting the error that nulls cannot be put in a not null column (`id`), however it doesn't seem to access to users table at all. It doesn't store the current order in users but it does generate the `orderId` and place it in orders along with the date. 

I thought maybe can stored procedures access only one table at a time or is there somewhere I need to specify which tables I need to access. Something about my connection string?

Asp.net:

```
public partial class PlaceOrder : System.Web.UI.Page
{
    SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["YIKESConnectionString"].ConnectionString);

    protected void Page_Load(object sender, EventArgs e)
    {
        string Name = Request.QueryString["Username"]; // retrieving username from the login page
        DateTime now = DateTime.Now;    // getting current date

        SqlCommand cmd = new SqlCommand("dbo.CreateOrder", con);
        con.Open();

        cmd.Parameters.Add("@Username", SqlDbType.VarChar).Value = Name;
        cmd.Parameters.Add("@DateOrdered", SqlDbType.Date).Value = now;
        cmd.Parameters.Add("@retord", System.Data.SqlDbType.Int).Direction = System.Data.ParameterDirection.ReturnValue;//return parameter
        cmd.CommandType = CommandType.StoredProcedure;

        cmd.ExecuteNonQuery();   // isn't accessing users at all, try one procedure for users one of orders
        con.Close();

        int orderid = (int)cmd.Parameters["@retord"].Value;
    }
}

```

SQL Server stored procedure:

```
CREATE PROCEDURE [dbo].[CreateOrder]
    @DateOrdered date,
    @Username varchar(16)
AS
    DECLARE @CurrentOrder int
    DECLARE @retord int

    SELECT @CurrentOrder = FLOOR(RAND() * (10000 - 0 + 1) + 0);

    UPDATE Users
    SET Users.CurrentOrder = @CurrentOrder
    WHERE Users.Username = @Username;

    INSERT INTO Orders(Orders.Id)
        SELECT Users.Id
        FROM Users
        WHERE Users.Username = @Username;

    INSERT INTO Orders(OrderId, DateOrdered)
    VALUES (@CurrentOrder, @DateOrdered);

    SELECT @retord = @CurrentOrder

    RETURN @retord

```

EDIT

Since the feedback, I've tested whether or not the username is being passed between pages and it's being passed as 2? what am i doing wrong here

Passing username

```
Response.Redirect("AccessDatabase.aspx?Username=" + usertxt.Text);

```

Retrieving username

```
string Name = Request.QueryString["Username"];

```