tag:blogger.com,1999:blog-6082652835152798567.post6724448446511864483..comments2024-03-28T21:41:58.974-07:00Comments on Sql server, .net and c# video tutorial: SqlDataReader object in ADO.NET - Part 8Unknownnoreply@blogger.comBlogger6125tag:blogger.com,1999:blog-6082652835152798567.post-44440438256644310242019-01-18T22:59:47.274-08:002019-01-18T22:59:47.274-08:00I'm getting following error while executing th...I'm getting following error while executing this program .Cannot implicitly convert type 'System.Data.SqlClient.SqlDataReader' to 'Test1.SqlDataReader'<br /><br />Plz helpAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-6082652835152798567.post-84143810102039755992017-09-21T00:26:22.088-07:002017-09-21T00:26:22.088-07:00//Hopefully This will help you.
//Take a class lib...//Hopefully This will help you.<br />//Take a class library named anything. But I've taken DAL. //That means Data Access Layer. Then...<br /><br />public static class DataAccess<br /> {<br /> #region User Authentication<br /> //Creating a boolean type method which will return only true or false depending on whether the Usernme and Password is matched or not;<br /> //Remember that this method will take values from the GUI textbox and then match it with the database using GetAccess() method below; <br /> public static bool isAuthenticatedUser(string paraSetUsername, string paraSetPassword)<br /> {<br /> bool isAuthentic = false;<br /> isAuthentic = GetAccess(paraSetUsername, paraSetPassword);//Here is the method GetAccess() below which take two parameters USername and Password<br /> return isAuthentic;<br /> }<br /><br /> //<br /> private static bool GetAccess(string paraGetUsername, string paraGetPassword) //These parameters will keep passing the value of user's input into the selected field!<br /> {<br /> string connectionString = "Data Source=.; Initial Catalog=YourDatabaseName; Integrated Security=True";<br /> SqlConnection conn;<br /> SqlCommand cmd;<br /> SqlDataReader dataReader;<br /> string sqlSUCKER = string.Format("SELECT pass FROM Register WHERE username = @username");<br /> string suckedHashedPassword = string.Empty;<br /> conn = new SqlConnection(connectionString);<br /> try<br /> {<br /> conn.Open();<br /> cmd = new SqlCommand(sqlSUCKER, conn);<br /> cmd.Parameters.AddWithValue("@username", paraGetUsername);<br /> dataReader = cmd.ExecuteReader();<br /><br /> while (dataReader.Read())<br /> {<br /> suckedHashedPassword = dataReader.GetValue(0).ToString();<br /> }<br /> if (SampleHash.SampleHash.VerifyHash(paraGetPassword, "SHA256", suckedHashedPassword.ToString()))<br /> {<br /> return true;<br /> }<br /> else<br /> return false;<br /> }<br /> catch (Exception ex)<br /> {<br /> return false;<br /> }<br /> finally<br /> {<br /> conn.Close();<br /> }<br /> }<br /> #endregion<br /> }sajeebhttps://www.blogger.com/profile/01471899088502889230noreply@blogger.comtag:blogger.com,1999:blog-6082652835152798567.post-88089722063527667032015-07-02T14:50:44.970-07:002015-07-02T14:50:44.970-07:00Hello Saleem,
You can create a custom object to h...Hello Saleem,<br /><br />You can create a custom object to hold the values returned from the SqlDataReader and return that to your application layer.<br /><br /><br />//Custom Class<br />public class myObject<br />{<br /> public string Name {get;set;}<br />}<br /><br />...<br /><br />In DataAccess Layer: <br /><br />public myObject GetValuesFromDatabase()<br />{<br /> //connection<br /> ...<br /> using(SqlDataReader rdr = command.ExecuteReader())<br />{<br /><br /> MyObject customObj = new MyObject();<br /> while( rdr.Read() )<br /> {<br /> customObj.Name = rdr["columnName"].ToString();<br /> }<br /> //Once you loop over the SqlDataReader and set the obj properties; return the object.<br /> return customObj;<br />}<br /><br />}Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-6082652835152798567.post-13240445313709418282015-01-07T02:06:54.668-08:002015-01-07T02:06:54.668-08:00Hi sir .
i want to know how to return sql dataread...Hi sir .<br />i want to know how to return sql datareader values like <br />In data Access Layer i have sql Data Reader.i want to read these values fro dr and populate these values on my application Layer..<br />Data Access Layer::<br /><br />sqldatareader dr=new sqlDatareader();<br />if(dr.read()){<br />dr[0].tostring();<br />.<br />.<br />dr[n].tostring();<br />------------------------<br />how these values i get on application layer?Anonymoushttps://www.blogger.com/profile/17897938771743285064noreply@blogger.comtag:blogger.com,1999:blog-6082652835152798567.post-12333635488310312782014-10-28T12:15:26.671-07:002014-10-28T12:15:26.671-07:00Mr.Venkat,
I am living in USA having 20+ years exp...Mr.Venkat,<br />I am living in USA having 20+ years experience in Controls Engineering. I salute you for all the help you are providing to fresh as well as experienced people.<br />Regards,<br />Your StudentAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-6082652835152798567.post-74370195373896693662014-01-24T06:58:23.379-08:002014-01-24T06:58:23.379-08:00Venkat Sir... you have changed many lives... thank...Venkat Sir... you have changed many lives... thanks for your efforts...Anonymousnoreply@blogger.com