Hi i have this query i use to select table Id, but the query is using Username to select the Id, please how do i correct that. What i want to achieve is this, i want to use the Id of a table to insert record into another table
code
protected void GetMergedAll_ItemCommand(object source, DataListCommandEventArgs e)
{
try
{
if (this.Page.User.Identity.IsAuthenticated)
{
string username = this.Page.User.Identity.Name;
string id = e.CommandArgument.ToString();
// string username6;
if (e.CommandName == "Insert")
{
//int userPostId = e.CommandArgument;
TextBox txtComments = (TextBox)e.Item.FindControl("txtComments");
// TextBox txtaddress = (TextBox)e.Item.FindControl("txtsaddress");
// TextBox txtrollno = (TextBox)e.Item.FindControl("txtsrollno");
SqlCommand cmd = new SqlCommand("InsertComment", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@MyComments", txtComments.Text);
//cmd.Parameters.AddWithValue("@UserName", username);
// cmd.Parameters.AddWithValue("@FriendUserName", username);
// cmd.Parameters.AddWithValue("@Id", id);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
cmd.Dispose();
Response.Write("<script type=\"text/javascript\">alert('Comment Posted Successfully!!!');</script>");
// BindDatalist(username);
}
}
}
catch (Exception ex)
{
throw ex;
}
}
procedure
ALTER PROCEDURE [dbo].[InsertComment](
@MyComments VARCHAR(MAX)
)
AS
BEGIN
DECLARE @Id INT;
SELECT @Id = u.Id FROM USERPost AS u WHERE u.Id = @Id
INSERT INTO UserCommentPost (postId,MyComments )
VALUES ( @Id, @MyComments)
END
Any help please