ASP.NET - CHECK REGISTERED
Asked By Rahul
03-Feb-12 03:09 AM
I WANT CORRECT QRY FOR CHECK ALREADY REGISTERED OR NOT IN TABLE THIS OR NOT ?
THIS WRONG QRY NA ?
cmd = new SqlCommand("select count(username) from agentreg", con);
kalpana aparnathi replied to Rahul
hi,
Try this way
cmd = new SqlCommand("select * from agentreg where user_id=@userID", con);
dipa ahuja replied to Rahul
protected void BtnLogin_Click(object sender, EventArgs e)
{
String conn = "<Your connectionSTring>";
SqlConnection connection = new SqlConnection(conn);
connection.Open();
string q = "select Count(*) from users where username='" + txtuname.Text + "'";
SqlCommand comm = new SqlCommand(q, connection);
int result = (int)comm.ExecuteScalar();
if (result > 0)
{
lblerror.Text = "User Already Exist!";
}
else
{
/*Insert new user to database */
}
connection.Close();
}

Make sure a file has been successfully uploaded If UploadedFile.PostedFile Is Nothing OrElse String.IsNullOrEmpty(UploadedFile.PostedFile.FileName) OrElse UploadedFile.PostedFile.InputStream Is Nothing Then . . . Show error message . . . e.Cancel name: " + FileUpload1.PostedFile.FileName + "<br> " ; / / Save ImageURL in Database string conn = ConfigurationManager .ConnectionStrings[ "ConnectionString" ].ConnectionString; SqlConnection connection = new SqlConnection (conn); connection.Open(); SqlCommand comm = new SqlCommand ( "Insert into Photos (iname, url) values (@iname, @url)" , connection); comm.Parameters.AddWithValue( "iname" , "photo1" ); comm.Parameters.AddWithValue( "url" , Path .GetFileName(FileUpload1.PostedFile.FileName)); comm.ExecuteNonQuery(); connection.Close(); } catch ( Exception ex) { Status.Text fs); image = reader.ReadBytes(( int )fs.Length); fs.Close(); string conn = ConfigurationManager .ConnectionStrings[ "ConnectionString" ].ConnectionString; SqlConnection connection = new SqlConnection (conn); connection.Open(); SqlCommand comm = new SqlCommand ( "Insert into Photos (iname, url
Table Name is : massMessage My column Names : id (int) message (varchar(MAX)) phone_no(nvarchar(20)) SqlConnection conn = new SqlConnection("Data Source = EN12-2-20-PC02 \ SQLEXPRESS;" + "Initial Catalog = ssms;Integrated Security = SSPI"); recepientNumber = <- -- - It message."; string mySQL = "Insert Into ozekimessageout (receiver, msg, status, sender) values (@receiver, @msg, @status, @sender)"; SqlCommand SqlInsert = new SqlCommand(mySQL, conn); SqlInsert.Parameters.AddWithValue("@receiver", r ecepientNumber ); <- -- - this should be the phone_no that needs to be send to(row by row) SqlInsert.Parameters.AddWithValue("@msg", toReply); SqlInsert.Parameters AddWithValue("@timetosend", this.showTime.Text); SqlInsert.Parameters.AddWithValue("@status", "send"); SqlInsert.Parameters.AddWithValue("@sender", this.lblShowUser.Text); conn.Open(); SqlInsert.ExecuteNonQuery(); conn.Close
retrive images from sql using sqldatareader and display image in label retrive images from sql using sqldatareader and display image in label? read image and show in label as The sample code follows public void ProcessRequest (HttpContext context) { SqlConnection myConnection = new SqlConnection(“YourConnectionString”); myConnection.Open(); string sql = "Select Image_Content from ImageGallery where Img_Id = @ImageId SqlCommand cmd = new SqlCommand(sql, myConnection); cmd.Parameters.Add("@ImageId", SqlDbType.Int).Value = context.Request.QueryString["id"]; cmd.Prepare(); SqlDataReader dr = cmd.ExecuteReader(); dr.Read(); string str; str = "<table> "; str = str + "<tr> <td> "; str = str Protected Sub Page_Load( ByVal sender As Object , ByVal e As EventArgs) Dim conn As New SqlConnection conn.ConnectionString = ConfigurationManager.ConnectionStrings.Item( "testConnectionString" ).ToString Dim strSql As String = "select * from pictable where
show image- / / connect with database where you have stored images public void ProcessRequest(HttpContext context) { SqlConnection cn = new SqlConnection("YOUR CONNECTION STRING"); cn.Open(); string empid = context.Request.QueryString["EmpID"].ToString(); SqlCommand cmd = new SqlCommand("select empimage from empimageTABLE where empid = " + empid, cn); SqlDataReader dr = cmd.ExecuteReader(); dr.Read(); context.Response.BinaryWrite((byte[])dr["empimage"]); dr.Close(); cn.Close HtmlImage)e.Item.Cells[ 0 ].FindControl( " imgPic" ); if (dsInsp ! = null && img ! = null && lblCode ! = null && !string.IsNullOrEmpty(lblCode.Text)) { / / select each row from the local datatable with the ID DataRow[] drowarr = dsInsp public class ImageHandler : IHttpHandler { public void ProcessRequest (HttpContext context) { string imageid = context.Request.QueryString["ImID"]; SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["connectionString"].ConnectionString); connection.Open(); SqlCommand command = new SqlCommand("select Image from Image where
Load lblLastUpdate.Text = DateAndTime.Now().ToString() Dim sqlstring As String = "spGetCallerID" Dim scon As New SqlConnection(sPWDBConn) scon.Open() Try Dim command As New SqlCommand(sqlstring, scon) command.CommandType = CommandType.StoredProcedure command.Parameters.AddWithValue("@UserName", Page.User.Identity.Name) Dim callerId As String = command.ExecuteScalar() If Not String IsNullOrEmpty(callerId) Then globalUserId = callerId sqlstring = "spShowTrafficTransitPref" Dim rs As SqlDataReader = Nothing command = New SqlCommand(sqlstring, scon) command.CommandType = CommandType.StoredProcedure command.Parameters.AddWithValue("@CallerID", globalUserId) rs = command.ExecuteReader Dim showTC As Boolean = False Dim showTR As Boolean = False showTR = rs("CheckTransit") End While End If rs.Close() command.Dispose() sqlstring = "spCheckUserHasTrips" command = New SqlCommand(sqlstring, scon) command.CommandType = CommandType.StoredProcedure command.Parameters.AddWithValue("@CallerID", globalUserId) Dim tripsexist As Integer