|
You already received some suggestions in your QA question at Creating remote desktop in WINAPI C++[^]. The authors of the youtube videos are the only people who can answer questions on what they suggest.
|
|
|
|
|
private void exprtbtn_Click(object sender, EventArgs e)
{
try
{
if ((this.dataGridView1.Rows.Count == 0))
{
MessageBox.Show("Please select Vouchers");
}
else
{
SqlConnection con = null;
SqlConnection con2 = null;
connClass cs = new connClass();
con = new SqlConnection(cs.distiConn1);
con2 = new SqlConnection(cs.sourceConn2);
ArrayList a = new ArrayList();
DataTable DT = new DataTable();
SqlCommand cmd = new SqlCommand();
SqlTransaction trans = default(SqlTransaction);
con.Open();
trans = con.BeginTransaction();
cmd.Connection = con;
cmd.Transaction = trans;
SqlCommand cmdLive = new SqlCommand();
cmdLive.Connection = con2;
SqlDataAdapter DR = default(SqlDataAdapter);
foreach (DataGridViewRow row in this.dataGridView1.Rows)
{
if ((((bool)(row.Cells[this.invoiceNO.Index].Value)) == true))
{
a.Add(row.Cells[this.invoiceNO.Index].Value);
}
}
int C = a.Count;
string str = "(";
int i = 0;
while (i < C - 1)
{
str += "'" + a[i] + "',";
i = i + 1;
}
str += "'" + a[C - 1] + "')";
cmdLive.CommandText = ("Select * from InvDailyHF where compno=1 and VouYear="
+ (this.yercombox.Text + (" and VouType="
+ (this.vochcombox.Text + (" and VouNo in " + str)))));
DR = new SqlDataAdapter(cmdLive);
DR.Fill(DT);
int CC = DT.Columns.Count;
string strn = "(";
int i1 = 0;
foreach (DataRow R in DT.Rows)
{
while (i1 < CC - 1)
{
strn += "'" + R[i1] + "',";
i1 = i1 + 1;
}
strn += "'" + R[CC - 1] + "')";
cmd.CommandText = ("Insert InvDailyHF values" + strn);
cmd.ExecuteNonQuery();
}
}
SqlConnection con3 = null;
SqlConnection con4 = null;
connClass csu = new connClass();
con3 = new SqlConnection(csu.sourceConn2);
con4 = new SqlConnection(csu.distiConn2);
ArrayList aH = new ArrayList();
DataTable DTH = new DataTable();
SqlCommand cmd1 = new SqlCommand();
SqlCommand cmdLiveh = new SqlCommand();
cmdLiveh.Connection = con3;
cmd1.Connection = con4;
SqlDataAdapter DAH = default(SqlDataAdapter);
foreach (DataGridViewRow row in this.dataGridView1.Rows)
{
if ((bool)row.Cells[this.invoiceNO.Index].Value == true)
{
aH.Add(row.Cells[this.invoiceNO.Index].Value);
}
}
int BB = aH.Count;
string strn1 = "(";
int i2 = 0;
while (i2 < BB - 1)
{
strn1 += "'" + aH[i2] + "',";
i2 = i2 + 1;
}
strn1 += "'" + aH[BB - 1] + "')";
cmdLiveh.CommandText = ("Select * from InvDailyDF where compno=1 and VouYear="
+ (this.yercombox.Text + (" and VouType="
+ (this.vochcombox.Text + (" and VouNo in " + strn1)))));
DAH = new SqlDataAdapter(cmdLiveh);
DAH.Fill(DTH);
int BB1 = DTH.Columns.Count;
string strn2 = "(";
int i3 = 0;
foreach (DataRow R in DTH.Rows)
{
while (i3 < BB1 - 1)
{
strn2 += "'" + R[i3] + "',";
i3 = i3 + 1;
}
strn2 += "'" + R[BB1 - 1] + "')";
}
cmd1.CommandText = ("Insert InvDailyDF values" + strn2);
cmd1.ExecuteNonQuery();
strn2 = "(";
i3 = 0;
ArrayList transData = new ArrayList();
DataTable transDT = new DataTable();
SqlCommand cmdTrans = new SqlCommand();
SqlDataAdapter transDR = new SqlDataAdapter();
int transCount;
int transCounter;
int DTcounter;
int iString;
string transDA = "(";
if (vochcombox.Text == "9")
{
cmdTrans.Connection = new SqlConnection(cs.sourceConn2);
foreach (DataGridViewRow row in this.dataGridView1.Rows)
{
if ((bool)row.Cells[this.invoiceNO.Index].Value == true)
{
transData.Add(row.Cells[this.invoiceNO.Index].Value);
}
}
transCount = transData.Count;
transDA = "(";
transCounter = 0;
while ((transCounter
< (transCount - 1)))
{
transDA = (transDA + ("\'"
+ (transData[transCounter] + ("\',"))));
transCounter = (transCounter + 1);
}
transDA = (transDA + ("\'"
+ (transData[(transCount - 1)] + "\')")));
cmdTrans.CommandText = ("Select * from glvodmf where vod_comp=1 and vod_year="
+ (this.yercombox.Text + (" and vod_type=4 and vod_num in " + transDA)));
transDR = new SqlDataAdapter(cmdTrans);
transDR.Fill(transDT);
DTcounter = transDT.Columns.Count;
transDA = "(";
iString = 0;
foreach (DataRow R in transDT.Rows)
{
while (iString
< (DTcounter - 1))
{
transDA = transDA + ("\'"
+ (R[iString] + "\',)"));
iString = (iString + 1);
}
transDA = (transDA + ("\'"
+ (R[(DTcounter - 1)] + "\')")));
cmdTrans.CommandText = ("Insert glvodmf values" + transDA);
cmdTrans.ExecuteNonQuery();
transDA = "(";
iString = 0;
}
}
else if (this.vochcombox.Text == "2")
{
cmdTrans.Connection = new SqlConnection(cs.sourceConn1);
foreach (DataGridViewRow row in this.dataGridView1.Rows)
{
if ((bool)row.Cells[this.invoiceNO.Index].Value == true)
{
transData.Add(row.Cells[this.invoiceNO.Index].Value);
}
}
transCount = transData.Count;
transDA = "(";
transCounter = 0;
while ((transCounter
< (transCount - 1)))
{
transDA = (transDA + ("\'"
+ (transData[transCounter] + ("\',"))));
transCounter = (transCounter + 1);
}
transDA = (transDA + ("\'"
+ (transData[(transCount - 1)] + "\')")));
cmdTrans.CommandText = ("Select * from glvodmf where vod_comp=1 and vod_year="
+ (this.yercombox.Text + (" and vod_type=6 and vod_num in " + transDA)));
transDR = new SqlDataAdapter(cmdTrans);
transDR.Fill(transDT);
DTcounter = transDT.Columns.Count;
transDA = "(";
iString = 0;
foreach (DataRow R in transDT.Rows)
{
while (iString
< (DTcounter - 1))
{
transDA = transDA + ("\'"
+ (R[iString] + "\',)"));
iString = (iString + 1);
}
transDA = (transDA + ("\'"
+ (R[(DTcounter - 1)] + "\')")));
cmdTrans.CommandText = ("Insert glvodmf values" + transDA);
cmdTrans.ExecuteNonQuery();
transDA = "(";
iString = 0;
}
}
else if (this.vochcombox.Text == "3")
{
cmdTrans.Connection = new SqlConnection(cs.sourceConn1);
foreach (DataGridViewRow row in this.dataGridView1.Rows)
{
if ((bool)row.Cells[this.invoiceNO.Index].Value == true)
{
transData.Add(row.Cells[this.invoiceNO.Index].Value);
}
}
transCount = transData.Count;
transDA = "(";
transCounter = 0;
while ((transCounter
< (transCount - 1)))
{
transDA = (transDA + ("\'"
+ (transData[transCounter] + ("\',"))));
transCounter = (transCounter + 1);
}
transDA = (transDA + ("\'"
+ (transData[(transCount - 1)] + "\')")));
cmdTrans.CommandText = ("Select * from glvodmf where vod_comp=1 and vod_year="
+ (this.yercombox.Text + (" and vod_type=8 and vod_num in " + transDA)));
transDR = new SqlDataAdapter(cmdTrans);
transDR.Fill(transDT);
DTcounter = transDT.Columns.Count;
transDA = "(";
iString = 0;
foreach (DataRow R in transDT.Rows)
{
while (iString
< (DTcounter - 1))
{
transDA = transDA + ("\'"
+ (R[iString] + "\',)"));
iString = (iString + 1);
}
transDA = (transDA + ("\'"
+ (R[(DTcounter - 1)] + "\')")));
cmdTrans.CommandText = ("Insert glvodmf values" + transDA);
cmdTrans.ExecuteNonQuery();
transDA = "(";
iString = 0;
}
}
else if (this.vochcombox.Text == "10")
{
cmdTrans.Connection = new SqlConnection(cs.sourceConn1);
foreach (DataGridViewRow row in this.dataGridView1.Rows)
{
if ((bool)row.Cells[this.invoiceNO.Index].Value == true)
{
transData.Add(row.Cells[this.invoiceNO.Index].Value);
}
}
transCount = transData.Count;
transDA = "(";
transCounter = 0;
while ((transCounter
< (transCount - 1)))
{
transDA = (transDA + ("\'"
+ (transData[transCounter] + ("\',"))));
transCounter = (transCounter + 1);
}
transDA = (transDA + ("\'"
+ (transData[(transCount - 1)] + "\')")));
cmdTrans.CommandText = ("Select * from glvodmf where vod_comp=1 and vod_year="
+ (this.yercombox.Text + (" and vod_type=9 and vod_num in " + transDA)));
transDR = new SqlDataAdapter(cmdTrans);
transDR.Fill(transDT);
DTcounter = transDT.Columns.Count;
transDA = "(";
iString = 0;
foreach (DataRow R in transDT.Rows)
{
while (iString
< (DTcounter - 1))
{
transDA = transDA + ("\'"
+ (R[iString] + "\',)"));
iString = (iString + 1);
}
transDA = (transDA + ("\'"
+ (R[(DTcounter - 1)] + "\')")));
cmdTrans.CommandText = ("Insert glvodmf values" + transDA);
cmdTrans.ExecuteNonQuery();
transDA = "(";
iString = 0;
}
}
else if (this.vochcombox.Text == "4")
{
cmdTrans.Connection = new SqlConnection(cs.sourceConn1);
foreach (DataGridViewRow row in this.dataGridView1.Rows)
{
if ((bool)row.Cells[this.invoiceNO.Index].Value == true)
{
transData.Add(row.Cells[this.invoiceNO.Index].Value);
}
}
transCount = transData.Count;
transDA = "(";
transCounter = 0;
while ((transCounter
< (transCount - 1)))
{
transDA = (transDA + ("\'"
+ (transData[transCounter] + ("\',"))));
transCounter = (transCounter + 1);
}
transDA = (transDA + ("\'"
+ (transData[(transCount - 1)] + "\')")));
cmdTrans.CommandText = ("Select * from glvodmf where vod_comp=1 and vod_year="
+ (this.yercombox.Text + (" and vod_type=13 and vod_num in " + transDA)));
transDR = new SqlDataAdapter(cmdTrans);
transDR.Fill(transDT);
DTcounter = transDT.Columns.Count;
transDA = "(";
iString = 0;
foreach (DataRow R in transDT.Rows)
{
while (iString
< (DTcounter - 1))
{
transDA = transDA + ("\'"
+ (R[iString] + "\',)"));
iString = (iString + 1);
}
transDA = (transDA + ("\'"
+ (R[(DTcounter - 1)] + "\')")));
cmdTrans.CommandText = ("Insert glvodmf values" + transDA);
cmdTrans.ExecuteNonQuery();
transDA = "(";
iString = 0;
}
}
else if (this.vochcombox.Text == "13")
{
cmdTrans.Connection = new SqlConnection(cs.sourceConn1);
foreach (DataGridViewRow row in this.dataGridView1.Rows)
{
if ((bool)row.Cells[this.invoiceNO.Index].Value == true)
{
transData.Add(row.Cells[this.invoiceNO.Index].Value);
}
}
transCount = transData.Count;
transDA = "(";
transCounter = 0;
while ((transCounter
< (transCount - 1)))
{
transDA = (transDA + ("\'"
+ (transData[transCounter] + ("\',"))));
transCounter = (transCounter + 1);
}
transDA = (transDA + ("\'"
+ (transData[(transCount - 1)] + "\')")));
cmdTrans.CommandText = ("Select * from glvodmf where vod_comp=1 and vod_year="
+ (this.yercombox.Text + (" and vod_type=14 and vod_num in " + transDA)));
transDR = new SqlDataAdapter(cmdTrans);
transDR.Fill(transDT);
DTcounter = transDT.Columns.Count;
transDA = "(";
iString = 0;
foreach (DataRow R in transDT.Rows)
{
while (iString
< (DTcounter - 1))
{
transDA = transDA + ("\'"
+ (R[iString] + "\',)"));
iString = (iString + 1);
}
transDA = (transDA + ("\'"
+ (R[(DTcounter - 1)] + "\')")));
cmdTrans.CommandText = ("Insert glvodmf values" + transDA);
cmdTrans.ExecuteNonQuery();
transDA = "(";
iString = 0;
}
}
else if (this.vochcombox.Text == "6")
{
cmdTrans.Connection = new SqlConnection(cs.sourceConn1);
foreach (DataGridViewRow row in this.dataGridView1.Rows)
{
if ((bool)row.Cells[this.invoiceNO.Index].Value == true)
{
transData.Add(row.Cells[this.invoiceNO.Index].Value);
}
}
transCount = transData.Count;
transDA = "(";
transCounter = 0;
while ((transCounter
< (transCount - 1)))
{
transDA = (transDA + ("\'"
+ (transData[transCounter] + ("\',"))));
transCounter = (transCounter + 1);
}
transDA = (transDA + ("\'"
+ (transData[(transCount - 1)] + "\')")));
cmdTrans.CommandText = ("Select * from glvodmf where vod_comp=1 and vod_year="
+ (this.yercombox.Text + (" and vod_type=61 and vod_num in " + transDA)));
transDR = new SqlDataAdapter(cmdTrans);
transDR.Fill(transDT);
DTcounter = transDT.Columns.Count;
transDA = "(";
iString = 0;
foreach (DataRow R in transDT.Rows)
{
while (iString
< (DTcounter - 1))
{
transDA = transDA + ("\'"
+ (R[iString] + "\',)"));
iString = (iString + 1);
}
transDA = (transDA + ("\'"
+ (R[(DTcounter - 1)] + "\')")));
cmdTrans.CommandText = ("Insert glvodmf values" + transDA);
cmdTrans.ExecuteNonQuery();
transDA = "(";
iString = 0;
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
modified 26-Dec-16 2:59am.
|
|
|
|
|
|
Specified cast is not valid.
|
|
|
|
|
So the Value of that cell cannot be cast to a bool type. You need to investigate why.
|
|
|
|
|
We can't tell without knowing what the error is - but it's most likely that this.invoiceNO.Index is trying to reference a cell that doesn't exist - it would be very unusual to have a table which held all invoices as vertical columns: normally it would be the row that is indexed to supply all the information for a single invoice, not the column:
Columns -> Invoice No Customer Date ItemsCost VAT TotalInvoiced
Rows 1001 Smiths 2016/12/14 102.37 20.47 122.84
| 1002 Johnson 2016/12/15 1247.99 ...
V 1003 Smiths 2016/12/15 742.65 ...
...
So use the debugger and see what value you have, and check the actual column data against that.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
this is debugger error(Specified cast is not valid.)
|
|
|
|
|
So use the debugger to look at the value of that cell and find out what type of data it contains. When you know that, you can start looking at why it isn't a boolean value.
We can't do that for you: we can't run your code, and don't have your data which fills the table if we could!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
did you have a time to take a look via teamviewr
|
|
|
|
|
Are you clinically insane?
You would allow total strangers you never met to remotely control your PC?
Have you any idea what some of them might do?
Have you ever heard of ransomware?
If you have that enabled, disable it immediately!
Use the debugger.
Look at the cell content. It should tell you a lot.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
no i'm not clinically insane.... but we are in a community to help each author.and i'm stacked.
|
|
|
|
|
We are in a community to help each other, but you have no idea who people are, and what they are going to do. This is the real world, and leaving your machine open for total strangers to access and do whatever they want - and if you give them access to VS that's exactly what they can do - is not "asking for trouble" it's inviting it indoors, giving it a beer, and telling it where you keep your credit cards!
Be realistic and honest: you know how to use the debugger, don't you? (If you don't, then say so and we'll try to get you started. But not telling us relevant information is just wasting your own time, as well as ours)
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
many thanks for your advice and your time.
|
|
|
|
|
You're welcome!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
i get my issue....
i need to get the value from DataGridView that was selected into array.
can you write to me example code.
|
|
|
|
|
Sorry, but I don't understand what you said: remember I only get exactly what you type to work from.
Can you explain in more detail, perhaps?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
i need code for get selected column value from datagridview into array list
//foreach (DataGridViewRow row in this.dataGridView1.Rows)
//{
// if ((((bool)(row.Cells[this.invoiceNO.Index].Value)) == true))
// {
// a.Add(row.Cells[this.invoiceNO.Index].Value);
// }
//}
|
|
|
|
|
The problem is that you aren't thinking about what is going on here: the value you are casting to a bool is not a bool value, so the cast fails: that can't be "fixed" at that point - you need to find out what it actually is and why it isn't the value you are expecting.
And the only way to do that is to use the debugger while your code is running and look at what the actual data looks like. No amount of code I could give you would fix that - because either the index is wrong, the data is wrong, the table isn't organised as you think it is, or it's totally the wrong table.
We can't tell you which of those: but the debugger probably can almost instantly!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
As long as you keep mixing "business logic" in with your "data access" logic, your life will continue to be difficult.
You are simply copying and pasting each "case", without any thought to the amount of duplicate code you are creating.
I would tell you to rewrite what you've got instead of helping you to "fix" it (and continuing to support your bad habits).
Or are you getting paid by lines-of-code?
|
|
|
|
|
Do you know in the Visual Studio programming webcam with standard library to the laptop's webcam ? what's the library name ? if attached great example.
|
|
|
|
|
You can use Google to answer this question, or search MSDN.
|
|
|
|
|
|
I created one table like this:
CREATE TABLE Pitanja
(
ID int NOT NULL IDENTITY (1,1) PRIMARY KEY,
Pitanje nvarchar(1000) NOT NULL,
Odgovor int NOT NULL,
OpcijaA nvarchar(1000) NOT NULL,
OpcijaB nvarchar(1000) NOT NULL,
OpcijaC nvarchar(1000) NOT NULL,
OpcijaD nvarchar(1000) NOT NULL
);
This is one part of table Pitanja
INSERT INTO Pitanja(Pitanje,Odgovor,OpcijaA,OpcijaB,OpcijaC,OpcijaD) VALUES('Blizu kog grada se nalaze Sremski Karlovci',3,'Rume','Sremske Mitrovice','Novog Sada','Šida');
Answers column contains number of correct choice,not word of correct choice.How to check answer when user select one of four choices from four buttons?
|
|
|
|
|
You could put the answers into an array like so:
string[] Answers = new string[4];
string UserChoice = Answers[IndexOfChoice];
Just set the variable IndexOfChoice to a number from 0 to 3 depending upon which button was clicked.
IndexOfChoice is an int.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
 Here is complete code:
int QuesionCount;
int IndexOfChoice;
DataTable dt = new DataTable();
int[] Answers = new int[4];
string cs= @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=c:\users\pavle\documents\visual studio 2015\Projects\Ko zna zna\Ko zna zna\Koznazna.mdf;Integrated Security=True";
private void Form1_Load(object sender, EventArgs e)
{
using (SqlConnection connection = new SqlConnection(cs))
{
string query = "SELECT * FROM Pitanja ORDER BY NEWID()";
SqlCommand command = new SqlCommand(query, connection);
try
{
connection.Open();
dt.Load(command.ExecuteReader());
connection.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
setQuestion();
}
private void provera()
{
int UserChoice = Answers[IndexOfChoice];
if (answer_id == UserChoice)
{
MessageBox.Show("Odgovor je tacan!");
}
else
{
MessageBox.Show("Odgovor nije tacan!");
}
}
private void button1_Click(object sender, EventArgs e)
{
Answers[IndexOfChoice] = 1;
provera();
}
private void button2_Click(object sender, EventArgs e)
{
Answers[IndexOfChoice] = 2;
provera();
}
private void button3_Click(object sender, EventArgs e)
{
Answers[IndexOfChoice] = 3;
provera();
}
private void button4_Click(object sender, EventArgs e)
{
Answers[IndexOfChoice] = 4;
provera();
}
private void button5_Click(object sender, EventArgs e)
{
try
{
this.QuesionCount++;
setQuestion();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
int answer_id;
private void setQuestion()
{
try
{
this.label2.Text = this.dt.Rows[this.QuesionCount]["Pitanje"].ToString();
this.button1.Text = this.dt.Rows[this.QuesionCount]["OpcijaA"].ToString();
this.button2.Text = this.dt.Rows[this.QuesionCount]["OpcijaB"].ToString();
this.button3.Text = this.dt.Rows[this.QuesionCount]["OpcijaC"].ToString();
this.button4.Text = this.dt.Rows[this.QuesionCount]["OpcijaD"].ToString();
this.label3.Text = this.dt.Rows[this.QuesionCount]["Odgovor"].ToString();
answer_id = Convert.ToInt32(this.dt.Rows[this.QuesionCount]["Odgovor"]);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
How to shuffle choises and keep track of the correct solution?
|
|
|
|