I am working on asp.net with oracle database. I want to print the image of employee which is saved in an old table. I don't even the data type of image saved in the photo field of that table.
I used Image handlers to print the images from newly created table but when I query on old tables the images is not getting printed.
How do I know that is there any image saved in the table?
If there is an image why it's not getting printed?
I'll show you the code for image handler for both the table (NEW , OLD) Image from newly created table is printing very fine but what's the problem in old one.
Can any give me any suggestions ?
Here is my ImgHandler.ashx code ;
public void ProcessRequest (HttpContext context)
{
OracleDataReader rdr = null;
OracleConnection conn = Conn.getConn();
OracleCommand cmd = null;
string ImgType = context.Request.QueryString["typ"].ToString();
try
{
if (ImgType=="edu")//this is working fine
{
cmd = new OracleCommand("select attachment pic from newtbl where lvldcp_code=" + context.Request.QueryString["dcp"] + "and emp_code="+context.Request.QueryString["emp"], conn);
}
else if (ImgType=="profile")
{
cmd = new OracleCommand("select photo pic from oldtbl where emp_code="+context.Request.QueryString["emp"], conn);
}
conn.Open();
rdr = cmd.ExecuteReader();
while (rdr.Read())
{
context.Response.ContentType = "image/jpg";
context.Response.BinaryWrite((byte[])rdr["pic"]);
}
if (rdr != null)
rdr.Close();
}
catch (Exception ex)
{
}
finally
{
if (conn != null)
conn.Close();
}
}
If your queries are returning a blob field value then you could use the OracleBlob class.
public void ProcessRequest (HttpContext context)
{
OracleDataReader rdr = null;
OracleConnection conn = Conn.getConn();
OracleCommand cmd = null;
string ImgType = context.Request.QueryString["typ"].ToString();
try
{
if (ImgType=="edu")//this is working fine
{
cmd = new OracleCommand("select attachment pic from newtbl where lvldcp_code=" + context.Request.QueryString["dcp"] + "and emp_code="+context.Request.QueryString["emp"], conn);
}
else if (ImgType=="profile")
{
cmd = new OracleCommand("select photo pic from oldtbl where emp_code="+context.Request.QueryString["emp"], conn);
}
Byte[] byteArray = null;
OracleBlob blob;
conn.Open();
rdr = cmd.ExecuteReader();
while (rdr.Read())
{
blob = rdr.GetOracleBlob(0);
byteArray = new Byte[blob.Length];
int i = blob.Read(byteArray, 0, System.Convert.ToInt32(blob.Length));
//clob.Length or i > 0 will show if there are bites in the clob or not
}
if (rdr != null)
rdr.Close();
context.Response.ContentType = "image/jpg";
context.Response.BinaryWrite(byteArray);
}
catch (Exception ex)
{
}
finally
{
if (conn != null)
conn.Close();
}
}
Related
I am using localDB as my database.
I have an employee table, and the employee images are stored in another table
This is my stored procedure for create and update:
IF NOT EXISTS (SELECT *
FROM dbo.Employee
WHERE employee_id=#employee_id)
BEGIN TRY
BEGIN TRAN
INSERT INTO dbo.Employee
(employee_name,
city,
department,
gender
)
OUTPUT inserted.employee_id
INTO #employee_id_PK (employee_id)
VALUES
(#employee_name,
#city,
#department,
#gender
)
SELECT #FK_Employee_Image_To_Employee_Table = employee_id
FROM #employee_id_PK
INSERT INTO dbo.Employee_Image
(user_image,
file_extension,
employee_id
)
VALUES
(#user_image,
#file_extension,
#FK_Employee_Image_To_Employee_Table
)
COMMIT TRAN
END TRY
BEGIN CATCH
IF ##TRANCOUNT > 0
ROLLBACK TRAN --RollBack in case of Error
RAISERROR (#ErrorMessage, #ErrorSeverity, #ErrorState);
END CATCH
ELSE
BEGIN TRY
BEGIN TRAN
UPDATE e
SET e.employee_name=#employee_name,
e.city=#city,
e.department=#department,
e.gender=#gender
FROM dbo.Employee e, dbo.Employee_Health_Insurance h
WHERE e.employee_id=#employee_id AND h.employee_id=#employee_id
UPDATE i
SET i.user_image=#user_image,
i.file_extension=#file_extension
FROM dbo.Employee_Image i, dbo.Employee e
WHERE i.employee_id=#employee_id AND e.employee_id=#employee_id
COMMIT TRAN
END TRY
BEGIN CATCH
IF ##TRANCOUNT > 0
ROLLBACK TRAN --RollBack in case of Error
RAISERROR (#ErrorMessage, #ErrorSeverity, #ErrorState);
END CATCH
This is how I add my records through C#
using (SqlConnection con = new SqlConnection(connectionStringConfig))
using (SqlCommand sqlCmd = new SqlCommand("spCreateOrUpdateData", con))
{
try
{
con.Open();
sqlCmd.CommandType = CommandType.StoredProcedure;
//Employee Record
sqlCmd.Parameters.Add("#employee_id", SqlDbType.NVarChar).Value = EmployeeId;
sqlCmd.Parameters.Add("#employee_name", SqlDbType.NVarChar, 250).Value = txtEmpName.Text;
sqlCmd.Parameters.Add("#city", SqlDbType.NVarChar, 50).Value = txtEmpCity.Text;
sqlCmd.Parameters.Add("#department", SqlDbType.NVarChar, 50).Value = txtEmpDept.Text;
sqlCmd.Parameters.Add("#gender", SqlDbType.NVarChar, 6).Value = cboEmpGender.Text;
//Employee Image
sqlCmd.Parameters.Add("#user_image", SqlDbType.VarBinary, 8000).Value = ConvertImageToByteArray(pictureBox1.Image); <-----------------error here according to StackTrace
sqlCmd.Parameters.Add("#file_extension", SqlDbType.VarChar, 12).Value = lblFileExtension.Text;
int numRes = sqlCmd.ExecuteNonQuery();
string ActionType = (btnSave.Text == "Save") ? "Saved" : "Updated";
if (numRes > 0)
{
MessageBox.Show($"{ txtEmpName.Text }'s record is { ActionType } successfully !!!");
RefreshData();
}
else
MessageBox.Show($"{txtEmpName.Text} Already Exist !!!");
}
catch (Exception ex)
{
MessageBox.Show($"Cannot INSERT or UPDATE data! \nError: { ex.Message }");
}
This is how I convert my image to byte[] array:
byte[] ConvertImageToByteArray(Image img)
{
//with memory stream:
/*[1]
using (MemoryStream ms = new MemoryStream())
{
img.Save(ms, img.RawFormat);<-----------------error here according to StackTrace
return ms.ToArray();
}*/
/*[2]
using (MemoryStream ms = new MemoryStream())
{
img.Save(ms, img.RawFormat);<-----------------error here according to StackTrace
byte[] arrImage = ms.GetBuffer();
return arrImage;
}*/
// with image converter
/*ImageConverter converter = new ImageConverter();
return (byte[])converter.ConvertTo(img, typeof(byte[]));*/ <-------------error here according to StackTrace
}
I have tried the above code when converting image to byte array, it is successful when I INSERT it to database, but when I UPDATE a record (e.g. changed the "Employee's name") without changing the image it will display an error: "A generic error occurred at GDI+."
EDIT:
Does it have something to do with retreiving the image?
I do not diplay my image binary data on my datagridview but I display/retreive my image like this:
private void dgvEmpDetails_CellClick(object sender, DataGridViewCellEventArgs e)
{
try
{
if (e.RowIndex != -1)
{
DataGridViewRow row = dgvEmpDetails.Rows[e.RowIndex];
EmployeeId = row.Cells[0].Value?.ToString();
txtEmpName.Text = row.Cells[1].Value?.ToString();
txtEmpCity.Text = row.Cells[2].Value?.ToString();
txtEmpDept.Text = row.Cells[3].Value?.ToString();
cboEmpGender.Text = row.Cells[4].Value?.ToString();
//Display user image
using (SqlConnection con = new SqlConnection(connectionStringConfig))
using (SqlCommand sqlCmd = new SqlCommand("SELECT user_image, file_extension FROM dbo.Employee_Image WHERE employee_id=#employee_id", con))
{
con.Open();
sqlCmd.Parameters.Add("#employee_id", SqlDbType.NVarChar).Value = EmployeeId;
using (SqlDataReader reader = sqlCmd.ExecuteReader())
{
if (reader.HasRows)
{
reader.Read();
pictureBox1.Image = ConvertByteArrayToImage((byte[])(reader.GetValue(0))); <------------- displaying the image here
lblFileExtension.Text = reader.GetValue(1).ToString();
}
else
{
pictureBox1.Image = null;
}
}
}
btnSave.Text = "Update";
btnDelete.Enabled = true;
}
}
catch (Exception ex)
{
MessageBox.Show($"Something is wrong with the selected record! \nError: { ex.GetType().FullName }");
}
}
My method in converting byte array to image:
public static Image ConvertByteArrayToImage(byte[] byteArrayIn)
{
using (MemoryStream ms = new MemoryStream(byteArrayIn))
{
Image returnImage = Image.FromStream(ms);
return returnImage;
}
}
I already solved this problem by modifying this approach: https://stackoverflow.com/a/14866755/11565087
This is my code for converting the image from my pictureBox into byte[]:
public static byte[] ImageToBytes(Image userImage)//Get bytes of the image
{
using (MemoryStream ms = new MemoryStream())
using (Bitmap tempImage = new Bitmap(userImage))
{
/*copy the object (userImage) into a new object (tempImage),
then use that object(tempImage) to "Write" */
tempImage.Save(ms, userImage.RawFormat);
return ms.ToArray();
}
}
This is my code for converting my image's binary data from the database and load it to my pictureBox:
public static Image BytesToImage(byte[] buffer) //Get image from database
{
using (MemoryStream ms = new MemoryStream(buffer))
{
return Image.FromStream(ms);
}
}
This is my approach for getting images from database
// This method use to update the form.
private void loadFormWithID(int ID)
{
dbServer conn = new dbServer(sysController.getConn);
DataTable tbl = conn.getQueryList("SELECT * FROM Products WHERE ID = " + ID);
DataRow row = tbl.Rows[0];
// This is how i update the Picture Box
pictureBoxItem.Image = row["Image"] == DBNull.Value ? pictureBoxItem.InitialImage : ImageController.bytesToImage((byte[])row["Image"]);
}
This is my dbserver class which communicates with database.
public class dbServer
{
public string _connectionLink;
public dbServer(string connectionString)
{
_connectionLink = connectionString;
}
public DataTable getQueryList(string sqlQuery)
{
DataTable tbl = new DataTable();
using (SqlConnection conn = new SqlConnection(_connectionLink))
{
using (SqlCommand cmd = new SqlCommand(sqlQuery, conn))
{
conn.Open();
SqlDataReader reader = cmd.ExecuteReader();
tbl.Load(reader);
}
}
return tbl;
}
}
I hope this solves the Issue.
When doubling clicking a row in datagrid object within the following windows form, the relevant information properly displays in a secondary form.
However I am not sure how to make it so that the image also displays in picturebox within the Student Form.
Here is the code so far:
public bool IsUpdate { get; set; }
private void StudentForm_Load(object sender, EventArgs e)
{
//For Update Process
if (this.IsUpdate == true)
{
using (SqlConnection con = new SqlConnection(AppConnection.GetConnectionString()))
{
using (SqlCommand cmd = new SqlCommand("usp_Student_ReloadDataForUpdate", con))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("#StudentName", this.StudentName);
if (con.State != ConnectionState.Open)
con.Open();
DataTable dtStudent = new DataTable();
SqlDataReader sdr = cmd.ExecuteReader();
dtStudent.Load(sdr);
DataRow row = dtStudent.Rows[0];
StudentNameTextBox.Text = row["StudentName"].ToString();
AgeTextBox.Text = row["Age"].ToString();
GenderTextBox.Text = row["Gender"].ToString();
DescriptionTextBox.Text = row["Description"].ToString();
//IdPictureBox.Image = row["Image"].???
SaveButton.Text = "Update Student Information";
DeleteButton.Enabled = true;
}
}
}
This follow is the stored procedure for the method above:
CREATE PROCEDURE usp_Student_ReloadDataForUpdate
(
#StudentName NVARCHAR(200)
)
AS
BEGIN
SELECT [StudentId]
,[StudentName]
,[Age]
,[Gender]
,[Description]
,[Image]
FROM [dbo].[Students]
WHERE StudentName = #StudentName
END
This is how the data is saved in the database
private void SaveButton_Click(object sender, EventArgs e)
{
if(IsFormValid())
{
//Do Update Process
using (SqlConnection con = new SqlConnection(AppConnection.GetConnectionString())) //connect to database using AppConnection class and GetConnectionString method
{
using (SqlCommand cmd = new SqlCommand("usp_Student_InsertNewStudent", con))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("#StudentName", StudentNameTextBox.Text.Trim());
cmd.Parameters.AddWithValue("#Age", AgeTextBox.Text.Trim());
cmd.Parameters.AddWithValue("#Gender", GenderTextBox.Text.Trim());
cmd.Parameters.AddWithValue("#Description", DescriptionTextBox.Text.Trim());
var image = IdPictureBox.Image;
using (var ms = new MemoryStream())
{
image.Save(ms, image.RawFormat);
cmd.Parameters.Add("#Image", SqlDbType.VarBinary).Value = ms.ToArray();
}
cmd.Parameters.AddWithValue("#CreatedBy", LoggedInUser.UserName);
if (con.State != ConnectionState.Open)
con.Open();
cmd.ExecuteNonQuery();
MessageBox.Show("Student is successfully updated in the database.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
ResetFormControl();
}
}
}
The data stored is a byte[] (Varbinary). You should convert it to an Image:
var pic = (byte[])row["Image"];
if (pic != null)
{
using (MemoryStream ms = new MemoryStream(pic))
{
IdPictureBox.Image = Image.FromStream(ms);
}
}
PS: I am not commenting on the rest of your code, like you shouldn't use AddWithValue but Add.
I want to export all photographs from our database into a data table. I will then loop through the table and save each image to disk. There are approx 7000 photos.
When I start the process I can retrieve around 4000 photographs before I start to get error messages like, Exception of type 'System.OutOfMemoryException' was thrown.
If I change the SQL query to retrieve half as many photographs, say 3500 then the process completes successfully.
While I have now achieved what I wanted by modifying the SQL each time I run the code, I would like to improve my code so that all 7000 photographs are returned. Could somebody please advise on a better process.
Here is my method
public static DataTable GetAllPhotos()
{
DataTable dt = new DataTable();
dt.Columns.Add("personId", typeof(string));
dt.Columns.Add("Photo", typeof(Bitmap));
string SQL = "";
byte[] getImg = new byte[0];
byte[] BitmapImg = new byte[0];
string personId = "";
SqlConnection conn = new SqlConnection();
conn.ConnectionString = _connString;
SQL = #"select per.person_id,pho.photo
from person as per
left join photo as pho on per.photo_id = pho.photo_id
where photo is not null";
conn.Open();
SqlDataReader dr = null;
SqlCommand cmd = new SqlCommand(SQL, conn);
dr = cmd.ExecuteReader();
while (dr.Read())
{
try
{
getImg = (byte[])dr["Photo"];
personId = Convert.ToString(dr["person_id"]);
MemoryStream str = new MemoryStream(getImg);
Bitmap bitmap = new Bitmap(Image.FromStream(str));
BitmapImg = ImageToByte(bitmap);
dt.Rows.Add(personId, bitmap);
}
catch (Exception ex)
{
LogWriter.WriteLine(personId + ex.Message.ToString());
}
}
conn.Close();
return dt;
}
If your intent is saving images to disk, then why would you get them into an intermediate datatable? Wouldn't it be better if you directly write out to disk as you read them? If so, assuming those are .bmp files:
public static void DumpAllPhotos()
{
string sql = #"select per.person_id,pho.photo
from person as per
inner join photo as pho on per.photo_id = pho.photo_id";
string folder = #"c:\MyFolder"; // output folder
using (SqlConnection con = new SqlConnection(_connString))
using (SqlCommand cmd = new SqlCommand(sql,con))
{
con.Open();
var rdr = cmd.ExecuteReader();
while (rdr.Read())
{
var bytes = (byte[])rdr["photo"];
var path = Path.Combine(folder, $"{rdr["person_id"].ToString()}.bmp");
File.WriteAllBytes(path, bytes);
}
con.Close();
}
}
Bitmap has to be disposed, you're using too many handles.
So your while loop should be something like this:
while (dr.Read())
{
try
{
getImg = (byte[])dr["Photograph"];
personId = Convert.ToString(dr["person_id"]);
MemoryStream str = new MemoryStream(getImg);
Bitmap bitmap = new Bitmap(Image.FromStream(str));
BitmapImg = ImageToByte(bitmap);
dt.Rows.Add(personId, bitmap);
bitmap.Dipose(); // <--- DISPOSE!!
}
catch (Exception ex)
{
LogWriter.WriteLine(personId + ex.Message.ToString());
}
}
or maybe even better:
while (dr.Read())
{
try
{
getImg = (byte[])dr["Photograph"];
personId = Convert.ToString(dr["person_id"]);
MemoryStream str = new MemoryStream(getImg);
using (Bitmap bitmap = new Bitmap(Image.FromStream(str))) {
BitmapImg = ImageToByte(bitmap);
dt.Rows.Add(personId, bitmap);
}
}
catch (Exception ex)
{
LogWriter.WriteLine(personId + ex.Message.ToString());
}
}
I have a problem with my SQL datareader, i want to make an external class and make the code in my xaml.cs as short as possible, because there are a lot of sqldatareaders needed in my program. for this I want to pass following two strings to the datareader class:
public void refreshcombobox()
{
cbGebruiker.Items.Clear();
database = new DataBase();
string sqlrdr = "(rdr.GetString(1).ToString().Trim())";
List<string> reader = database.ReaderRdr("Select * from Gebruikers", ref sqlrdr);
foreach (String str in reader)
{
cbGebruiker.Items.Add(str);
}
}
however, when I do this this is the result in my program instead of the actual results that are stored in the database:
http://i58.tinypic.com/301j2vo.jpg (I can't post images)
can somebody help me with this? I've searched everywhere...
I don't know how to pass the rdr.GetString(1).ToString().Trim() to make it actually look stuff up in the db. Instead of just copying the string directly into the list.
This is the class:
namespace ClassLib
{
public class DataBase
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["kassadatabase"].ConnectionString);
public object ScalarObject(string sql)
{
object value = null;
try
{
conn.Open();
SqlCommand cmd = new SqlCommand(sql, conn);
value = cmd.ExecuteScalar();
}
catch (SqlException ex)
{
MessageBox.Show(ex.Message);
}
finally
{
if (conn != null) conn.Close();
}
return value;
}
public List<string> ReaderRdr(string sql)
{
SqlDataReader rdr = null;
List<string> reader = new List<string>();
try
{
conn.Open();
SqlCommand cmd = new SqlCommand(sql, conn);
rdr = cmd.ExecuteReader();
while (rdr.Read())
{
//reader.Add(rdr.GetString(1).ToString().Trim());
}
}
catch (SqlException ex)
{
MessageBox.Show(ex.Message);
}
finally
{
if (rdr != null) rdr.Close();
if (conn != null) conn.Close();
}
return reader;
}
//public List<string> ReaderRdr(string sql, ref string str)
//{
// SqlDataReader rdr = null;
// List<string> reader = new List<string>();
// try
// {
// conn.Open();
// SqlCommand cmd = new SqlCommand(sql, conn);
// rdr = cmd.ExecuteReader();
// while (rdr.Read())
// {
// //MessageBox.Show(str.ToString());
// //var strRdr = str;
// //MessageBox.Show(strRdr.ToString());
// //reader.Add(rdr.GetString(1).ToString().Trim());
// reader.Add(str);
// Console.WriteLine(String.Format("{0}", rdr[0]));
// }
// }
// catch (SqlException ex)
// {
// MessageBox.Show(ex.Message);
// }
// finally
// {
// if (rdr != null) rdr.Close();
// if (conn != null) conn.Close();
// }
// return reader;
//}
public void ExecuteNQuery(string insertString)
{
try
{
conn.Open();
SqlCommand cmd2 = new SqlCommand(insertString, conn);
cmd2.ExecuteNonQuery();
}
catch (SqlException ex)
{
MessageBox.Show(ex.Message);
}
finally
{
if (conn != null) conn.Close();
}
}
}
}
public List<string> ReaderRdr(string sql)
{
SqlDataReader rdr = null;
List<string> reader = new List<string>();
try
{
conn.Open();
SqlCommand cmd = new SqlCommand(sql, conn);
rdr = cmd.ExecuteReader();
while (rdr.Read())
{
//reader.Add(rdr.GetString(1).ToString().Trim());
}
.....
now in the methode public list i want to replace the //reader.Add(rdr.GetString(1).ToString().Trim()); part(wich works fine)
with a string that is passed to the method.
public List<string> ReaderRdr(string sql, string strRdr)
{
SqlDataReader rdr = null;
List<string> reader = new List<string>();
try
{
conn.Open();
SqlCommand cmd = new SqlCommand(sql, conn);
rdr = cmd.ExecuteReader();
while (rdr.Read())
{
//reader.Add(strRdr);
}
I'm not 100% sure what you're trying to do, but I can tell you right now that this is what you're doing wrong - the string (str) you're passing to ReaderRdr is just a string literal of C# code. There's super hacky (super inadvisable) things you can do to mimic what exists in other languages as eval(), but there's no built-in way to do that in C#. Nothing (sensible) you do to "(rdr.GetString(1).ToString().Trim())" is ever going to get a string, or cast it to string, or trim anything.
Within your ReaderRdr function, all you're accomplishing is just to add the string str to your List<string> reader. This accomplishes nothing and has no bearing whatsoever on the results you get from your database query in your SqlDataReader rdr. If you want to store the data you actually get from your database, use rdr, not the (useless) string argument str.
Also, I feel like you must have left something out of your code - you're instantiating your SqlCommand cmd with conn as your second argument, but I don't see that defined anywhere within your ReaderRdr method, and it's not an argument passed to ReaderRdr. You don't have an SqlConnection object as a field or property within your class, do you?
As far as what you should maybe do, despite lacking much of any context in terms of your actual aims - if you want to get any given column of the result for each row returned by your SqlDataReader:
rdr = cmd.ExecuteReader();
while (rdr.Read())
{
var yourDataCell = rdr[yourColumnIndex];
// or:
var yourDataCellOtherWay = rdr["YourColumnName"];
}
Alternately, you can just iterate through each of the cells in any given row produced by your SqlDataReader like so:
for(int i = 0 ; i < numberOfColumns; i++) {
// do something with rdr[i] here
}
I'm not sure if there's anything you can do establish numberOfColumns based on the state of your SqlDataReader, but others might know better.
You actually adding the String that you passed to a function to your reader reader.Add(str); You get the response from SQL I your rdr.
This item will show you something from your database:
Console.WriteLine(String.Format("{0}", rdr[0]));
I have a DataClassLibrary attached to my ASP.Net project. I use it to access the database to get my values. I want to take the values given in the Line1 class and put them in the corresponding label. I tried DataLibraryClass.Line1 NewDataA = new DataLibraryClass.Line1(); but it gives me a zero I know that they have values. Could it be that my NewDataA = new is causing it to return zero? I also used breakpoints in the Line1 class and it never reaches the database query. How can I get the data I need into the labels properly?
DataLibraryClass
Line1:
var sqlString = new StringBuilder();
sqlString.Append("SELECT CaseNum6, CaseNum9, Group, Completion ");
sqlString.Append("FROM WorkOrder ");
sqlString.Append("WHERE Group = 1 OR Group = 2 ");
sqlString.Append("AND Completion = 0 ");
SqlDataReader reader = null;
SqlConnection dbConn = DBHelper.getConnection();
SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("#CaseNum6", CaseNum6 )};
try
{
reader = DBHelper.executeQuery(dbConn, sqlString.ToString(), parameters);
if (reader != null)
{
if (reader.Read())
{
CaseNum6 = (int)reader["CaseNum6"];
CaseNum9 = (int)reader["CaseNum9"];
Group = (int)reader["Group"];
Completion = (bool)reader["Completion"];
}
else
throw new Exception("No record returned");
reader.Close();
reader.Dispose();
dbConn.Close();
dbConn.Dispose();
DataLibraryClass
DBHelper:
private DBHelper() { }
public static SqlConnection getConnection()
{
return new SqlConnection(ConfigurationManager.ConnectionStrings["Connection"].ConnectionString);
}
public static SqlConnection getFRESHConnection()
{
return new SqlConnection(ConfigurationManager.ConnectionStrings["FRESHConnection"].ConnectionString);
}
public static SqlDataReader executeQuery(SqlConnection dbConn, string sqlString, SqlParameter[] parameters)
{
SqlCommand cmd = null;
SqlDataReader reader = null;
try
{
if (dbConn.State == ConnectionState.Closed)
dbConn.Open();
cmd = dbConn.CreateCommand();
cmd.CommandText = sqlString;
if (parameters != null)
{
cmd.Parameters.AddRange(parameters);
}
reader = cmd.ExecuteReader();
cmd.Dispose();
}
catch (Exception ex)
{
throw ex;
}
return reader;
Code behind ASP page:
DataClassLibrary.LineAData NewDataA = new DataClassLibrary.LineAData();
DataClassLibrary.LineBData NewDataB = new DataClassLibrary.LineBData();
protected void Page_Load(object sender, EventArgs e)
{
L1.Text = NewDataA.CaseNum6.ToString();
L2.Text = NewDataA.CaseNum9.ToString();
L4.Text = NewDataB.CaseNum6.ToString();
L5.Text = NewDataB.CaseGNum9.ToString();
}
Upon setting up the webpage I failed to realize the behind code was set to .vb not .cs which is why everything was not working.