Related
This is my code:
{
string To = Server.HtmlEncode(Request.Cookies["userInfo"]["Email"]).ToString();
string name = Server.HtmlEncode(Request.Cookies["userInfo"]["Name"]).ToString();
string Subject = "IQC Non-leather Status";
string email_body = "Item has been checked by QC with the following details.. ";
string sImage = System.Web.HttpContext.Current.Server.MapPath("~/Content/Uploads/image.jpg");
DataTable dtqc = new ifs_ShipmentInfo_DAL().qc_po_info(site, IQC_STORE_SL);
email_body += #"<table>";
if (dtqc.Rows.Count > 0)
This is the mail body:
{
DataRow dr = dtqc.Rows[0];
email_body += "<tr><td>Supplier Name</td><td>:</td><td>" + Convert.ToString(dr["SUPPLIER_NAME"]) + "</td></tr>";
email_body += "<tr><td>PO NO</td><td>:</td><td>" + Convert.ToString(dr["PO_NO"]) + "</td></tr>";
email_body += "<tr><td>Invoice No</td><td>:</td><td>" + Convert.ToString(dr["COMMERCIAL_INV_NO"]) + "</td></tr>";
email_body += "<tr><td>Invoice recvd date</td><td>:</td><td>" + Convert.ToString(dr["DATE_OF_RECEIVING"]) + "</td></tr>";
email_body += "<tr><td>Part No</td><td>:</td><td>" + Convert.ToString(dr["PART_NO"]) + "</td></tr>";
email_body += "<tr><td>Part Description</td><td>:</td><td>" + Convert.ToString(dr["PART_DESC"]) + "</td></tr>";
email_body += "<tr><td>Invoice Qnty</td><td>:</td><td>" + Convert.ToString(dr["INVOICE_QTY"]) + "</td></tr>";
email_body += "<tr><td>Final Result</td><td>:</td><td>" + INSPECTION_RESULT + "</td></tr>";
email_body += "<tr><td>Reason</td><td>:</td><td>" + insRemarks + "</td></tr>"
+ "<tr><td>Inspected Qnty</td><td>:</td><td>" + INSPECTION_QTY + "</td></tr>"
+ "<tr><td>Accepted Qnty</td><td>:</td><td>" + ACCEPTED_QTY + "</td></tr>"
+ "<tr><td>Rejected Qnty</td><td>:</td><td>" + REJECTED_QTY + "</td></tr>"
+ "<tr><td>Fully Rejected Qnty</td><td>:</td><td>" + FINAL_REJECTED_QTY + "</td></tr>"
+ "<tr><td>Inspected By</td><td>:</td><td>" + INSPECTED_BY + "</td></tr>"
Trying to send image like this:
+ "<tr><td>Defective Picture</td><td>:</td><td><img src='" + sImage + "'width='100'height='100'alt='img'style='margin:20px 0px 0px 20px'/></td></tr>";
}
email_body += "</table>";
I am trying to solve an error ,I created a variable to b store data that is in an Excel sheet. The error occurs when I try to insert the data that in SQL Server, in the query. Thanks for the help .
Code: variable declaration:
String valmoradafiscaligualmoradalocal = "";
Information search code:
Case 47: // column 21
If ((WS.Cells [row, Collation] as Excel.Range) .Value)! = Null)
{
Valmoradafiscaligualmoradalocal = Convert.ToString ((WS.Cells [row, Contcoluna] as Excel.Range) .Value);
}
continue;
Insert code in sql server:
}
break;
}
If (WS! = Null)
{
SqlCommand cmd = new SqlCommand ();
cmd.CommandText = "INSERT tabela_sacc (Grupo,Tipo_de_Instalacao,SubGrupo,Nr_Cliente,Data_Entidade,Situacao_da_entidade,Tipo_Entidade,Nome,Contribuinte,Tipo_Documento,Numero_Documento,Nr_Ident,Cod_Cliente_Sistema_Antigo,Entidade_Pagadora,Nome_Entidade_Pagadora,Numero_Contrato,Data_Contrato,Tipo_Contrato,Tipo_Sensibilidade,Tipo_de_Fatura,Nivel_de_Contador,Morada_de_Envio,Localizacao,Tipo_de_Medicao_Telemetria,Data_Vigencia,Ultimo_Dia_Estimado,Ultimo_Dia_Real,Ultimo_Dia_Faturado,Data_Ultima_Fatura,Data_Proxima_Fatura,Data_Situacao,Consumo_Medio_Real,Estimativa,Grupo_Contador,N_Contador,N_Referencia_Contador,Selos_do_Contador,Data_Instalacao,Leit_Cont_Simples_a_Data_Inst,Leit_Cont_Secundaria_a_Data_Inst,Leit_Cont_Principal_a_Data_Inst,Numero_Fabricante,Fabricante,Modelo_do_Contador,Calibre,Morada_Fiscal_Igual_a_Morada_Local,N_Rua_A,Rua_A,Policia_A,Andar_A,Localidade_A,Freguesia_A,Cod_Postal_A,Des_Postal_A,Zona_Postal_A,N_Rua_C,Rua_C,Policia_C,Andar_C,Localidade_C,Freguesia_C,Cod_Postal_C,Des_Postal_C,Zona_Postal_C,Nome_Fatura,N_da_Instalacao,N_Predio,Ramal,Ramal_Associado,Ramal_Saneamento,Anotacoes,Anotacoes_Ramal_Saneamento,Zona_Abastecimento,ZMC,Classe_Consumo,Tipo_Consumo,Grupo_Tarifario,Situacao,Zona,Area,Local,Local_em_Vigor,Tipo_Abastecimento,Caracteristica_Local,Calibre_Local,Local_Totalizador) VALUES ('" + valgrupo + "','" + valsubgrupo + "' ,'" + valtpinstalacao.ToString() + "','" + valnrcliente + "','" + valdataentidade.ToString("MM/dd/yyyy") + "','" + valsituacaoentidade + "','" + valtpentidade + "','" + valnome + "','" + valcontrbuinte + "','" + valtpdoc + "','" + valndoc + "','" + valnridentidade + "','" + valcodclisistemaantigo + "','" + valentidadepagadora + "','" + valnomeentidadepagadora + "','" + valncontrato + "','" + valdatacontrato.ToString("MM/dd/yyyy") + "','" + valtpcontrato + "','" + valtpsensibilidade + "','" + valtpfatura + "','" + valnivelcontador + "','" + valmoradaenvio + "','" + vallocalizacao + "','" + valtpmedicaotelemetria + "','" + valdatavigencia.ToString("MM/dd/yyyy") + "','" + valultimodiaestimado.ToString("MM/dd/yyyy") + "','" + valultimodiareal.ToString("MM/dd/yyyy") + "','" + valultimodiafaturado.ToString("MM/dd/yyyy") + "','" + valdataultimafatura.ToString("MM/dd/yyyy") + "','" + valdataproximafatura.ToString("MM/dd/yyyy") + "','" + valdatasituacao.ToString("MM/dd/yyyy") + "','" + valconsumomedioreal + "','" + valestimativa + "','" + valgrupocontador + "','" + valncontador + "','" + valnreferenciacontador + "','" + valselocontador + "','" + valdatainstalacao.ToString("MM/dd/yyyy") + "','" + valleiturasimplescontadoradatainst + "','" + valleituraprincipalcontadoradatainst + "','" + valleiturasecundariacontadoradatainst + "','" + valnrfabricante + "','" + valfabricante + "','" + valmodelocontador + "','" + valcalibre + "','" + valmoradafiscaligualmoradalocal.ToString() + "','" + valnruaa + "','" + valruaa + "','" + valpoliciaa + "','" + valandara + "','" + vallocalidadea + "','" + valfreguesiaa + "','" + valcodposltala + "','" + valdespostala + "','" + valzonapostala + "','" + valnruac + "','" + valruac + "','" + valpoliciac + "','" + valandarc + "','" + vallocalidadec + "','" + valfreguesiac + "','" + valcodpostalc + "','" + valdespostalc + "','" + valzonapostalc + "','" + valnomefatura + "','" + valninstalacao + "','" + valnpredio + "','" + valramal + "','" + valramalassociado + "','" + valramalsaneamento + "','" + valanotacoes + "','" + valanotacoesramalsaneamento + "','" + valzonaabastecimento + "','" + valzmc + "','" + valclasseconsumo + "','" + valtipoconsumo + "','" + valgrupotarifario + "','" + valsituacao + "','" + valzona + "','" + valarea + "','" + vallocal + "','" + vallocalemvigor + "','" + valtpabastecimento + "','" + valcaracteristicalocal + "','" + valcalibrelocal + "','" + vallocaltotalizador + "')";
Connection.Open();
Cmd.Connection = connection;
Cmd.CommandType = CommandType.Text;
Cmd.ExecuteNonQuery();
Connection.Close();
valmoradafiscaligualmaradalocal= null;
break;
}
}
MessageBox.Show ("end");
}
}
I think you need to check the column in SQL, because seems like the 'morada_Fiscal_Igual_a_Morada_Local' column is a tinyint type and not a text to get the string "Não"
If you are trying to make a boolean type, use the type "bit"
For now, you can make this:
"VALUES ('" + valmoradafiscaligualmoradalocal.ToString() == "Não" ? "0" : "1" + "')"
PS: Na proxima vez preste atenção, se o campo for um tinyint, ou bit, quer dizer que ele quer receber 0 ou 1, assim como em um campo de verdadeiro ou falso.
I need a google map to have responsiveness for both computer and smartphone. I need to show only Slovak Republic to the edge of any device's width. Currently, I am using lng and lat to determine the center of the country.
My complete javascript:
//<![CDATA[
var customIcons = {
1: {
icon: '/img/map-marker-icon.png'
},
0: {
icon: '/img/map-marker-icon.png'
}
};
function load() {
var map = new google.maps.Map(document.getElementById("map"), {
center: new google.maps.LatLng(48.730556, 19.457222),
zoom: 8,
scrollwheel: false,
mapTypeId: 'roadmap'
});
var infoWindow = new google.maps.InfoWindow;
// Change this depending on the name of your PHP file
downloadUrl("phpsqlajax_genxml2.php", function(data) {
var xml = data.responseXML;
var markers = xml.documentElement.getElementsByTagName("marker");
for (var i = 0; i < markers.length; i++) {
// MAX MEETINGS = 10
var num1 = markers[i].getAttribute("num1");
var nazov1 = markers[i].getAttribute("nazov1");
var popis1 = markers[i].getAttribute("popis1");
var foto1 = markers[i].getAttribute("photo1");
var datum1 = markers[i].getAttribute("datum1");
var num2 = markers[i].getAttribute("num2");
var nazov2 = markers[i].getAttribute("nazov2");
var popis2 = markers[i].getAttribute("popis2");
var foto2 = markers[i].getAttribute("photo2");
var datum2 = markers[i].getAttribute("datum2");
var num3 = markers[i].getAttribute("num3");
var nazov3 = markers[i].getAttribute("nazov3");
var popis3 = markers[i].getAttribute("popis3");
var foto3 = markers[i].getAttribute("photo3");
var datum3 = markers[i].getAttribute("datum3");
var num4 = markers[i].getAttribute("num4");
var nazov4 = markers[i].getAttribute("nazov4");
var popis4 = markers[i].getAttribute("popis4");
var foto4 = markers[i].getAttribute("photo4");
var datum4 = markers[i].getAttribute("datum4");
var num5 = markers[i].getAttribute("num5");
var nazov5 = markers[i].getAttribute("nazov5");
var popis5 = markers[i].getAttribute("popis5");
var foto5 = markers[i].getAttribute("photo5");
var datum5 = markers[i].getAttribute("datum5");
var num6 = markers[i].getAttribute("num6");
var nazov6 = markers[i].getAttribute("nazov6");
var popis6 = markers[i].getAttribute("popis6");
var foto6 = markers[i].getAttribute("photo6");
var datum6 = markers[i].getAttribute("datum6");
var num7 = markers[i].getAttribute("num7");
var nazov7 = markers[i].getAttribute("nazov7");
var popis7 = markers[i].getAttribute("popis7");
var foto7 = markers[i].getAttribute("photo7");
var datum7 = markers[i].getAttribute("datum7");
var num8 = markers[i].getAttribute("num8");
var nazov8 = markers[i].getAttribute("nazov8");
var popis8 = markers[i].getAttribute("popis8");
var foto8 = markers[i].getAttribute("photo8");
var datum8 = markers[i].getAttribute("datum8");
var setp = 0;
var idloc = markers[i].getAttribute("idloc");
var mesto = markers[i].getAttribute("mesto");
var lat = markers[i].getAttribute("lat");
var point = new google.maps.LatLng(
parseFloat(markers[i].getAttribute("lat")),
parseFloat(markers[i].getAttribute("lng")));
// IF SET PHOTO
if (foto1 == "") { var photo1 = "<img src='/img/nophoto.jpg' border='0' alt='" + popis1 + "' />"; var link1 = "<a href='/img/nophotobig.jpg' data-lightbox='" + num1 + "' title='" + nazov1 + "<br />Datum: " + datum1 + "<br />Popis: " + popis1 + "' class='morephotos'>Zobraziť popis</a>"; } else { var link1 = "<a href='" + foto1 + "' data-lightbox='" + num1 + "' title='" + nazov1 + "<br />Datum: " + datum1 + "<br />Popis: " + popis1 + "' class='morephotos'>Zobraziť popis+fotky</a>"; var photo1 = "<div class='cover' style='background-image:url(" + foto1 + ");'> </div>"; }
if (foto2 == "") { var photo2 = "<img src='/img/nophoto.jpg' border='0' alt='" + popis2 + "' />"; var link2 = "<a href='/img/nophotobig.jpg' data-lightbox='" + num2 + "' title='" + nazov2 + "<br />Datum: " + datum2 + "<br />Popis: " + popis2 + "' class='morephotos'>Zobraziť popis</a>"; } else { var link2 = "<a href='" + foto2 + "' data-lightbox='" + num2 + "' title='" + nazov2 + "<br />Datum: " + datum2 + "<br />Popis: " + popis2 + "' class='morephotos'>Zobraziť popis+fotky</a>"; var photo2 = "<div class='cover' style='background-image:url(" + foto2 + ");'> </div>"; }
if (foto3 == "") { var photo3 = "<img src='/img/nophoto.jpg' border='0' alt='" + popis3 + "' />"; var link3 = "<a href='/img/nophotobig.jpg' data-lightbox='" + num3 + "' title='" + nazov3 + "<br />Datum: " + datum3 + "<br />Popis: " + popis3 + "' class='morephotos'>Zobraziť popis</a>"; } else { var link3 = "<a href='" + foto3 + "' data-lightbox='" + num3 + "' title='" + nazov3 + "<br />Datum: " + datum3 + "<br />Popis: " + popis3 + "' class='morephotos'>Zobraziť popis+fotky</a>"; var photo3 = "<div class='cover' style='background-image:url(" + foto3 + ");'> </div>"; }
if (foto4 == "") { var photo4 = "<img src='/img/nophoto.jpg' border='0' alt='" + popis4 + "' />"; var link4 = "<a href='/img/nophotobig.jpg' data-lightbox='" + num4 + "' title='" + nazov4 + "<br />Datum: " + datum4 + "<br />Popis: " + popis4 + "' class='morephotos'>Zobraziť popis</a>"; } else { var link4 = "<a href='" + foto4 + "' data-lightbox='" + num4 + "' title='" + nazov4 + "<br />Datum: " + datum4 + "<br />Popis: " + popis4 + "' class='morephotos'>Zobraziť popis+fotky</a>"; var photo4 = "<div class='cover' style='background-image:url(" + foto4 + ");'> </div>"; }
if (foto5 == "") { var photo5 = "<img src='/img/nophoto.jpg' border='0' alt='" + popis5 + "' />"; var link5 = "<a href='/img/nophotobig.jpg' data-lightbox='" + num5 + "' title='" + nazov5 + "<br />Datum: " + datum5 + "<br />Popis: " + popis5 + "' class='morephotos'>Zobraziť popis</a>"; } else { var link5 = "<a href='" + foto5 + "' data-lightbox='" + num5 + "' title='" + nazov5 + "<br />Datum: " + datum5 + "<br />Popis: " + popis5 + "' class='morephotos'>Zobraziť popis+fotky</a>"; var photo5 = "<div class='cover' style='background-image:url(" + foto5 + ");'> </div>"; }
if (foto6 == "") { var link6 = "<a href='/img/nophotobig.jpg' data-lightbox='" + num6 + "' title='" + nazov6 + "<br />Datum: " + datum6 + "<br />Popis: " + popis6 + "' class='morephotos'>Zobraziť popis</a>"; var photo6 = "<img src='/img/nophoto.jpg' border='0' alt='" + popis6 + "' />"; } else { var link6 = "<a href='" + foto6 + "' data-lightbox='" + num6 + "' title='" + nazov6 + "<br />Datum: " + datum6 + "<br />Popis: " + popis6 + "' class='morephotos'>Zobraziť popis+fotky</a>"; var photo6 = "<div class='cover' style='background-image:url(" + foto6 + ");'> </div>"; }
if (foto7 == "") { var link7 = "<a href='/img/nophotobig.jpg' data-lightbox='" + num7 + "' title='" + nazov7 + "<br />Datum: " + datum7 + "<br />Popis: " + popis7 + "' class='morephotos'>Zobraziť popis</a>"; var photo7 = "<img src='/img/nophoto.jpg' border='0' alt='" + popis7 + "' />"; } else { var link7 = "<a href='" + foto7 + "' data-lightbox='" + num7 + "' title='" + nazov7 + "<br />Datum: " + datum7 + "<br />Popis: " + popis7 + "' class='morephotos'>Zobraziť popis+fotky</a>"; var photo7 = "<div class='cover' style='background-image:url(" + foto7 + ");'> </div>"; }
if (foto8 == "") { var link8 = "<a href='/img/nophotobig.jpg' data-lightbox='" + num8 + "' title='" + nazov8 + "<br />Datum: " + datum8 + "<br />Popis: " + popis8 + "' class='morephotos'>Zobraziť popis</a>"; var photo8 = "<img src='/img/nophoto.jpg' border='0' alt='" + popis8 + "' />"; } else { var link8 = "<a href='" + foto8 + "' data-lightbox='" + num8 + "' title='" + nazov8 + "<br />Datum: " + datum8 + "<br />Popis: " + popis8 + "' class='morephotos'>Zobraziť popis+fotky</a>"; var photo8 = "<div class='cover' style='background-image:url(" + foto8 + ");'> </div>"; }
if (datum1 !== null) { var section1 = "<section><br />" + photo1 + " <p>Dňa: <strong>" + datum1 + "</strong><br />" + link1 + "</p><div class='clear'></div></section>"; } else { var section1 = ""; }
if (datum2 !== null) { var section2 = "<section><br />" + photo2 + " <p>Dňa: <strong>" + datum2 + "</strong><br />" + link2 + "</p><div class='clear'></div></section>"; } else { var section2 = ""; }
if (datum3 !== null) { var section3 = "<section><br />" + photo3 + " <p>Dňa: <strong>" + datum3 + "</strong><br />" + link3 + "</p><div class='clear'></div></section>"; } else { var section3 = ""; }
if (datum4 !== null) { var section4 = "<section><br />" + photo4 + " <p>Dňa: <strong>" + datum4 + "</strong><br />" + link4 + "</p><div class='clear'></div></section>"; } else { var section4 = ""; }
if (datum5 !== null) { var section5 = "<section><br />" + photo5 + " <p>Dňa: <strong>" + datum5 + "</strong><br />" + link5 + "</p><div class='clear'></div></section>"; } else { var section5 = ""; }
if (datum6 !== null) { var section6 = "<section><br />" + photo6 + " <p>Dňa: <strong>" + datum6 + "</strong><br />" + link6 + "</p><div class='clear'></div></section>"; } else { var section6 = ""; }
if (datum7 !== null) { var section7 = "<section><br />" + photo7 + " <p>Dňa: <strong>" + datum7 + "</strong><br />" + link7 + "</p><div class='clear'></div></section>"; } else { var section7 = ""; }
if (datum8 !== null) { var section8 = "<section><br />" + photo8 + " <p>Dňa: <strong>" + datum8 + "</strong><br />" + link8 + "</p><div class='clear'></div></section>"; } else { var section8 = ""; }
var html = "<div class='locationwindow'>" + section1 + " " + section2 + " " + section3 + " " + section4 + " " + section5 + " " + section6 + " " + section7 + " " + section8 + "<div class='clear'></div><hr />Miesto stretnutia: <strong> " + mesto + " </strong></div>";
var icon = customIcons[setp] || {};
var marker = new google.maps.Marker({
map: map,
position: point,
icon: icon.icon
});
bindInfoWindow(marker, map, infoWindow, html);
}
});
}
google.maps.event.addDomListener(window, 'resize', initialize);
google.maps.event.addDomListener(window, 'load', initialize)
function bindInfoWindow(marker, map, infoWindow, html) {
google.maps.event.addListener(marker, 'click', function() {
infoWindow.setContent(html);
infoWindow.open(map, marker);
});
}
function downloadUrl(url, callback) {
var request = window.ActiveXObject ?
new ActiveXObject('Microsoft.XMLHTTP') :
new XMLHttpRequest;
request.onreadystatechange = function() {
if (request.readyState == 4) {
request.onreadystatechange = doNothing;
callback(request, request.status);
}
};
request.open('GET', url, true);
request.send(null);
}
function doNothing() {}
My CSS
#map {
margin: 0;
padding: 0;
height: 800px;
z-index:4;
width: 100%;
}
I am trying to fill a list from a database. Here is my code:
string cur = dInstructorSelect.SelectedValue.Substring(dInstructorSelect.SelectedValue.IndexOf(" - ") + 3);
SqlCommand cmdInsCourses = new SqlCommand("select * from CourseTable where InstructorID=#cur", con);
cmd.Parameters.AddWithValue("#cur", cur);
SqlDataAdapter da = new SqlDataAdapter(cmdInsCourses);
DataTable dt = new DataTable();
da.Fill(dt);
Here, i declare a string variable cur, which returns 4 as i expect. The problem is, when i debugged, there is an error saying that Must declare the scalar variable "#cur". I cannot see what is problematic here. Can anyone help?
Thanks
Edit: Here is the full code:
SqlConnection con = new SqlConnection();
con.ConnectionString = Userfunctions.GetConnectionString();
int result;
string queryCourseCount = "select count (*) from CourseTable";
SqlCommand countCommand = new SqlCommand(queryCourseCount, con);
con.Open();
int courseCount = 1001 + Convert.ToInt32(countCommand.ExecuteScalar());
string crn = (MyGlobals.currentYear % 100).ToString() + (MyGlobals.currentTerm == "Spring" ? 2 : 1) + courseCount.ToString().Substring(1, 3);
string instructor = dInstructorSelect.SelectedValue.Substring(dInstructorSelect.SelectedValue.IndexOf(" - ")+3);
string subject = dSubject.SelectedValue, courseNumber=tCourse.Text, courseName= tCourseName.Text ;
string courseDescription = tCourseDescription.Text, capacity=tCapacity.Text;
string currentTerm=MyGlobals.currentTerm + " " + MyGlobals.currentYear.ToString();
string level=dLevel.SelectedValue, credit=tCredit.Text;
string query1 = "insert into CourseTable(InstructorID,CourseCode,CourseNumber,CourseName,Term, CRN,Level,Credit,Description,Capacity) values(#instructor,#subject,#courseNumber,#courseName,#currentTerm,#crn,#level,#credit,#courseDescription,#capacity)";
SqlCommand cmd = new SqlCommand(query1, con);
cmd.Parameters.AddWithValue("#instructor", instructor);
cmd.Parameters.AddWithValue("#subject", subject);
cmd.Parameters.AddWithValue("#courseNumber", courseNumber);
cmd.Parameters.AddWithValue("#courseName", courseName);
cmd.Parameters.AddWithValue("#currentTerm", currentTerm);
cmd.Parameters.AddWithValue("#crn", crn);
cmd.Parameters.AddWithValue("#level", level);
cmd.Parameters.AddWithValue("#credit", credit);
cmd.Parameters.AddWithValue("#courseDescription", courseDescription);
cmd.Parameters.AddWithValue("#capacity", capacity);
string query2 = "";
string query3 = "";
if (cbPreq1.Checked)
{
query2 = "insert into PrereqTable(CourseCode,CourseNumber,Term,pCourseCode,pCourseNumber) values ('"
+ dSubject.SelectedValue + "'" + "," + "'" + tCourse.Text + "'" + "," + "'" + MyGlobals.currentTerm + " " + MyGlobals.currentYear.ToString()
+ "'" + "," + "'" + dPrereq1.SelectedValue.Substring(0, dPrereq1.SelectedValue.Length - 3) + "'" + "," + "'" + dPrereq1.SelectedValue.Substring(dPrereq1.SelectedValue.Length - 3, 3) + "'" + ")";
}
if (cbPreq2.Checked)
{
query3 = "insert into PrereqTable(CourseCode,CourseNumber,Term,pCourseCode,pCourseNumber) values ('"
+ dSubject.SelectedValue + "'" + "," + "'" + tCourse.Text + "'" + "," + "'" + MyGlobals.currentTerm + " " + MyGlobals.currentYear.ToString()
+ "'" + "," + "'" + dPrereq2.SelectedValue.Substring(0, dPrereq2.SelectedValue.Length - 3) + "'" + "," + "'" + dPrereq2.SelectedValue.Substring(dPrereq2.SelectedValue.Length - 3, 3) + "'" + ")";
}
string query4="";
if (cbtime1.Checked)
{
query4 = "insert into TimeTable(CourseCode, CourseNumber, Term, StartHour, EndHour, Day) values ('"
+ dSubject.SelectedValue + "'" + "," + "'" + tCourse.Text + "'" + "," + "'" + MyGlobals.currentTerm + " " + MyGlobals.currentYear.ToString()
+ "'" + "," + "'" + dHourStart.SelectedValue + "'" + "," + "'" + dHourEnd.SelectedValue + "'" + "," + "'" + dDay.SelectedValue + "'" + ")";
}
string query5 = "";
if (cbtime2.Checked)
{
query5 = "insert into TimeTable(CourseCode, CourseNumber, Term, StartHour, EndHour, Day) values ('"
+ dSubject.SelectedValue + "'" + "," + "'" + tCourse.Text + "'" + "," + "'" + MyGlobals.currentTerm + " " + MyGlobals.currentYear.ToString()
+ "'" + "," + "'" + dHourStart2.SelectedValue + "'" + "," + "'" + dHourEnd2.SelectedValue + "'" + "," + "'" + dDay2.SelectedValue + "'" + ")";
}
string query6="";
if (cbtime3.Checked)
{
query6 = "insert into TimeTable(CourseCode, CourseNumber, Term, StartHour, EndHour, Day) values ('"
+ dSubject.SelectedValue + "'" + "," + "'" + tCourse.Text + "'" + "," + "'" + MyGlobals.currentTerm + " " + MyGlobals.currentYear.ToString()
+ "'" + "," + "'" + dHourStart3.SelectedValue + "'" + "," + "'" + dHourEnd3.SelectedValue + "'" + "," + "'" + dDay3.SelectedValue + "'" + ")";
}
SqlCommand cmd1, cmd2, cmd3, cmd4, cmd5, cmd6;
bool correctTime = false;
List<String> timeTable = new List<string>();
List<Course>instCourses = new List<Course>();
string tableName = "InstructorTable";
// String name = "", surname = "", email = "";
// CreateUser(con, tableName, ref name, ref surname, ref email);
// MyGlobals.instructor = new Instructor(Convert.ToInt32(idBox.Text), "Active", email, name, surname, passwordBox.Text);
string cur = dInstructorSelect.SelectedValue.Substring(dInstructorSelect.SelectedValue.IndexOf(" - ") + 3);
SqlCommand cmdInsCourses = new SqlCommand("select * from CourseTable where InstructorID=#cur", con);
cmd.Parameters.AddWithValue("#cur", cur);
SqlDataAdapter da = new SqlDataAdapter(cmdInsCourses);
DataTable dt = new DataTable();
da.Fill(dt);
Note: I know there are some queries that are not parametrized, i will fix them.
Try prefixing your parameter with #:
cmdInsCourses.Parameters.AddWithValue("#cur", cur);
Try adding the scalar variable "#cur" rather than "cur":
cmd.Parameters.AddWithValue("#cur", cur);
Try like this...
SqlCommand cmdInsCourses =
new SqlCommand("select * from CourseTable where InstructorID=#cur", con);
cmdInsCourses.Parameters.Add("cur", SqlDbType.VarChar).Value = cur;
EDIT : The Problem lies that you are adding parameters to cmd, not to cmdInsCourses, I have changed the code, just look into that.
I want to enter a DATE to my ACCESS DB, the field is DATE/TIME.
The user enter it in a form in this method (text) DD/MM/YYYY
The code:
DATE/TIME object
DateTime Bday = new DateTime(long.Parse(Request.Form["Bday"]));
The SQL QUERY:
cmd.CommandText = "INSERT INTO (Fname,Lname,User,Pass,Email,BiDate,IsAdmin,IsMale) VALUES ('" + fname + "','" + lname + "','" + user + "','" + pass + "','" + email + "',#" + Bday + "#," + admin + "," + male + ")";
Its not working
Remove the long.Parse part
DateTime Bday = DateTime.ParseExact(Request.Form["Bday"], "dd/MM/yyyy",
CultureInfo.InvariantCulture);
cmd.CommandText = "INSERT INTO (Fname,Lname,[User],Pass,Email,BiDate,"
+"IsAdmin,IsMale) " +
"VALUES ('" + fname + "','" + lname + "','" + user + "','" + pass + "','"
+ email + "',#" + Bday.ToString("dd/MM/yyyy") + "#," + admin + "," + male + ")";
Hope this helps!