|
|
Hi, I am a beginner c# programmer and still having problems with my DataReader.
I searched and tried several codes but no positive result.
So I decided to post some parts from my sql, asp, cs code project.
The problem area is commented //.
I would be very greatful if anyone helped me giving specific recomendation how to fix that issue.
===========================================================
CREATE TABLE `images`
(
`Image_ID` int(32) NOT NULL AUTO_INCREMENT,
`Image` blob,
PRIMARY KEY (`Image_ID`)
)
ENGINE=InnoDB AUTO_INCREMENT=3608 DEFAULT CHARSET=binary;
============================================================
CREATE TABLE `groups`
(
`Group_ID` char(02) NOT NULL,
`Number` varchar(5) DEFAULT NULL,
PRIMARY KEY (`Group_ID`)
)
ENGINE=InnoDB DEFAULT CHARSET=utf8;
============================================================
CREATE TABLE `register`
(
`ID` int(32) NOT NULL AUTO_INCREMENT,
`Arrive_Img_ID` int(32) DEFAULT NULL,
`Leave_Img_ID` int(32) DEFAULT NULL,
`Students_ID` char(2) DEFAULT NULL,
PRIMARY KEY (`ID`),
KEY `FK_register_ArriveImg` (`Arrive_Img_ID`),
KEY `FK_register_LeaveImg` (`Leave_Img_ID`),
KEY `FK_register_Students` (`Students_ID`),
KEY `Date` (`Date`),
CONSTRAINT `FK_register_ArriveImg` FOREIGN KEY (`Arrive_Img_ID`) REFERENCES `images` (`Image_ID`) ON DELETE SET NULL ON UPDATE SET NULL,
CONSTRAINT `FK_register_LeaveImg` FOREIGN KEY (`Leave_Img_ID`) REFERENCES `images` (`Image_ID`) ON DELETE SET NULL ON UPDATE SET NULL,
CONSTRAINT `FK_register_Students` FOREIGN KEY (`Students_ID`) REFERENCES `students` (`Students_ID`) ON DELETE CASCADE ON UPDATE CASCADE
)
ENGINE=InnoDB AUTO_INCREMENT=2248 DEFAULT CHARSET=utf8;
==============================================================
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ImageRetrieve.aspx.cs" Inherits="ImageRetrieve" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.auto-style1 {
width: 100%;
}
.auto-style2 {
width: 389px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
<br />
<br />
<br />
<table class="auto-style1">
<tr>
<td class="auto-style2">
<asp:DropDownList ID="ddlGroup" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddlGroup1_SelectedIndexChanged">
</asp:DropDownList>
</td>
<td> </td>
</tr>
<tr>
<td class="auto-style2">
<asp:DropDownList ID="ddlName" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddlName_SelectedIndexChanged">
</asp:DropDownList>
</td>
<td> </td>
</tr>
<tr>
<td class="auto-style2">
</td>
<td>
<asp:GridView ID="gvImages" runat="server" AllowSorting="True" AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333" GridLines="None" OnRowDataBound="OnRowDataBound" Width="105px">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:BoundField DataField="Image_ID" HeaderText="Image_ID" />
<asp:TemplateField HeaderText="Image">
<ItemTemplate>
<asp:Image ID="Image1" runat="server" Height="80" Width="80" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F5F7FB" />
<SortedAscendingHeaderStyle BackColor="#6D95E1" />
<SortedDescendingCellStyle BackColor="#E9EBEF" />
<SortedDescendingHeaderStyle BackColor="#4870BE" />
</asp:GridView>
</td>
</tr>
</table>
<br />
</form>
</body>
</html>
====================================================================================================
using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class ImageRetrieve : System.Web.UI.Page
{
string constr = "Data Source=localhost;port=3306;Initial Catalog=test;User Id=root;password=2525";
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindGroupdropdown();
}
}
protected void BindGroupdropdown()
{
MySqlConnection con = new MySqlConnection(constr);
con.Open();
MySqlCommand cmd = new MySqlCommand("select * from groups", con);
MySqlDataAdapter da = new MySqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
con.Close();
ddlGroup.DataSource = ds;
ddlGroup.DataTextField = "Number";
ddlGroup.DataValueField = "Number";
ddlGroup.DataBind();
ddlGroup.Items.Insert(0, new ListItem("--Select--", "0"));
ddlName.Items.Insert(0, new ListItem("--Select--", "0"));
}
private string getGroupID()
{
MySqlConnection con = new MySqlConnection(constr);
con.Open();
MySqlCommand cmd = new MySqlCommand("select Group_ID from groups where Number='" + ddlGroup.SelectedValue + "'", con);
string appid = (cmd.ExecuteScalar() ?? String.Empty).ToString();
con.Close();
return appid;
}
protected void ddlGroup1_SelectedIndexChanged(object sender, EventArgs e)
{
string aid = getGroupID();
MySqlConnection con = new MySqlConnection(constr);
con.Open();
MySqlCommand cmd = new MySqlCommand("select CONCAT(SurName , ' ', Name , ' ', MiddleName) AS SNM from students where Group_ID='" + aid + "'", con);
MySqlDataAdapter da = new MySqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
con.Close();
ddlName.DataSource = ds;
ddlName.DataTextField = "SNM";
ddlName.DataValueField = "SNM";
ddlName.DataBind();
ddlName.Items.Insert(0, new ListItem("--Select--", "0"));
BindGrid();
}
private string getStudent_ID()
{
var SNM = ddlName.Text.Replace("'", "''");
MySqlConnection con = new MySqlConnection(constr);
con.Open();
MySqlCommand cmd = new MySqlCommand("Select Students_ID from students where CONCAT(SurName , ' ', Name , ' ', MiddleName)='" + SNM + "'");
cmd.Connection = con;
String s = (cmd.ExecuteScalar() ?? String.Empty).ToString();
con.Close();
return s;
}
private void BindGrid()
{
MySqlConnection con = new MySqlConnection(constr);
MySqlCommand cmd = new MySqlCommand("SELECT Image_ID, Image FROM images where Image_ID='" + getImage_ID() + "'", con);
MySqlDataAdapter da = new MySqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
gvImages.DataSource = dt;
gvImages.DataBind();
}
protected void OnRowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
byte[] bytes = (byte[])(e.Row.DataItem as DataRowView)["Image"];
string base64String = Convert.ToBase64String(bytes, 0, bytes.Length);
(e.Row.FindControl("Image1") as Image).ImageUrl = "data:image/png;base64," + base64String;
}
}
private string getImage_ID()
{
MySqlConnection con = new MySqlConnection(constr);
con.Open();
MySqlCommand cmd = new MySqlCommand("Select Arrive_Img_ID,Leave_Img_ID from register where Students_ID='" + getStudent_ID() + "'");
cmd.Connection = con;
MySqlDataReader reader = cmd.ExecuteReader();
//Here I can't find suitable code to call multiple results from register table.
//return s;
}
protected void ddlName_SelectedIndexChanged(object sender, EventArgs e)
{
BindGrid();
}
}
|
|
|
|
|
For starters, never concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Use Parametrized queries instead.
Then just use your reader object:
while(reader.Read())
{
Console.WriteLine(reader["Arrive_img_ID"]);
Console.WriteLine(reader["Leave_img_ID"]);
}
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
I want to import documents from the scanner in my MVC web application and use optical character recognition to fetch the data.
I am not willing to use any expensive libraries like TWAIN, dynamsoft, Atalasoft, LeadTools, Asprise, etc..
I looked for Microsoft OCR, but it seems the library only works for Windows Store Apps.
Please suggest me some good yet free/cheap library for scanning and OCR in MVC web application.
|
|
|
|
|
The server can't access hardware on the client. If you're googling for OCR libraries that can be used with MVC you're not going to find anything.
|
|
|
|
|
You could try Tesseract. A .NET wrapper is available here[^].
/ravi
|
|
|
|
|
Can you provide me with bit more details about Tesseract for .net. Didn't get much documentation about it.
|
|
|
|
|
See this[^] link for instructions.
/ravi
|
|
|
|
|
when i extracted BLOB data from database i can see like this in my word doc.
how to convert it to readable format?
o � 8 A+ ¬ 2
e �
o � ¬ 2
e
o � Cleveland, OH : & + & % / . H F
2
e ( o � �) � o ' �� � �� � @ Garamond - 2 2
� P o � Management Trainee ProgramZ 0 7 0 6 / S /
|
|
|
|
|
That depends on what it is!
If it's a Word document, then save it as a .DOC or .DOCX file, and get Word to open it. Presumably, when you saved the data you also saved a file name with it?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Yes correct..i am saving it as .DOC
when i am opening, it is asking conversion from "Encoding text" and when i select "Unicode" it is displaying like that
|
|
|
|
|
Try an experiment: upload a known-working file, and then save it as a different name. Compare the two and see if there are any differences.
If there are, then you need to start by looking at how you are storing it and make sure that works first.
But...DOC files aren't all Unicode - they can be a binary format, so doing an Unicode conversion is probably going to mess them up.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Chances are that even inside your Word document and this web page there are many things that messed up the format, made it even worse.
The binary object that you captured was indeed an array of bytes containing the data (I won't say it was initially a Word document) with a format to be taken care of while converting back to a valid file. That is why whenever you store a file in the image type (in SQL image is the binary data, not the image you know) you also store the file extension or MIME type (the thing you know as "application/json" etc.). They are used to convert that data back to files.
When you copied the data, it was not of Word format, every file has its own structure that is followed when converting the bytes back to a representation of the file. Word was not able to convert it back to actual representation, in which case it showed you that broken format.
Notice that most of the content, such as those characters were easily mapped and thus they were shown to you, but a few other stuff was not mapped. Simple as that.
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
Ya correct..few content not mapped and some of the content mapped..tried dfferent options from Word ponit of view..but no luck
|
|
|
|
|
Was the file initially of Word format (.doc or .docx; Rich Text Format is a separate case)?
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
Yes..I am sure..its .DOC only..
|
|
|
|
|
I would recommend that you create the file using the stream (read the binary data using the SELECT) and then convert the stream (of binary data) to a file. In simple words, follow what OriginalGriff said above.
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
hi
i know how to work with Keystroke and i know how to send any keboard typing
to any open windows to focus place the cursor on local computer.
i work with GlobalKeyboardHook
now, i need to send some data to open windows on focus place using RDP
for any computer that in my net.
how to do it ? my solution dont work
(i work on C# visual-studio 2010 WinForm)
|
|
|
|
|
What are you trying to do on the remote machine?
SendKeys does not work over RDP and GlobalKeyboardHooks are for capturing keystrokes on the machine it's running on, not for sending to another machine.
|
|
|
|
|
hi i had learn c++ and something about the framework Qt but the problem that the Qt is not used for building apps smartphone like C# or JAVA !!
so do u advice me to leave c++ and Qt and start with C# or JAVA ??
please i need your Advice Thank you
|
|
|
|
|
Pick one place and post there, not in QA, C++, and C#.
Otherwise, you duplicate work and annoy people.
You have this posted in QA, so leave it there.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Don't different people participate in these forums though? There may be folks who only check the C# or say the C++ forums, and others who only check QA. I would think it's alright to cross-post in this situation.
|
|
|
|
|
Indeed, this is true. For a discussion, I would have said that this forum was a far more appropriate choice than QA.
|
|
|
|
|
hello all,
I am creating a list of textbox's dynamically using list and also have added a ok button and created a click_event for the button. But how will i fetch the textbox content that was created dynamically thru the click event of the button. Please see the code below :
public static List<string> InpBox(string title, List<string>prompt, ref string value, int TxtCnt)
{
Form form = new Form();
Button buttonOk = new Button();
Button buttonCancel = new Button();
List<string> inputTexts = new List<string>();
List<textbox> inputTextBoxes = new List<textbox>();
form.AutoSizeMode = AutoSizeMode.GrowAndShrink;
form.AutoSize = true;
form.Padding = new Padding(0, 0, 20, 20);
form.FormBorderStyle = FormBorderStyle.FixedDialog;
form.StartPosition = FormStartPosition.CenterScreen;
form.MinimizeBox = false;
form.MaximizeBox = false;
form.AcceptButton = buttonOk;
form.CancelButton = buttonCancel;
form.Text = title;
for (int i = 1; i <= TxtCnt; i++)
{
Label labelInput = new Label();
TextBox textBoxNewInput = new TextBox();
labelInput.Text = prompt[i-1];
labelInput.Location = new Point(0, (i * 30));
labelInput.AutoSize = true;
System.Drawing.SizeF sizeF = new System.Drawing.SizeF();
System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(new System.Drawing.Bitmap(1, 1));
sizeF = graphics.MeasureString(labelInput.Text, new System.Drawing.Font("Arial,Verdana,Helvetica,sans-serif", 10, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point));
int maxTextWidthinPixel = Convert.ToInt32(sizeF.Width);
textBoxNewInput.Location = new Point(maxTextWidthinPixel - 20, labelInput.Top - 3);
textBoxNewInput.Width = 372;
inputTextBoxes.Add(textBoxNewInput);
form.Controls.Add(labelInput);
form.Controls.Add(textBoxNewInput);
}
buttonOk.Text = "OK";
buttonCancel.Text = "Cancel";
buttonOk.Location = new Point(form.Width / 2 - buttonOk.Width / 2, inputTextBoxes[inputTextBoxes.Count - 1].Bottom + 20);
buttonCancel.Location = new Point((form.Width / 2 + buttonOk.Width / 2)+10, inputTextBoxes[inputTextBoxes.Count - 1].Bottom + 20);
form.Controls.Add(buttonOk);
form.Controls.Add(buttonCancel);
buttonOk.DialogResult = DialogResult.OK;
buttonCancel.DialogResult = DialogResult.Cancel;
buttonOk.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonOk.Click += new EventHandler(buttonOk_Click);
form.ClientSize = new Size(396, 135);
DialogResult dialogResult = form.ShowDialog();
return inputTexts;
}
assistance needed. Thanks in advance
Antony,
ansonel@gmail.com
|
|
|
|
|
Since you create a number of textboxes (which is probably a poor idea - have a look at a DataGridView or similar instead, it does most of the work for you) you will have to search for them (or use the inputTextBoxes collection you added them to).
Searching is relatively simple - they are in the form Controls array along with all the others - but I'd just look in your collection! Just move it to a private class level variable and access it in your Click event handler.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|