My problem when I use MySQL server, the calendar was appear but when I change the connection to SQL server the calendar doesn't appear. I have no idea how to solve this problem. Is that anything that I have to change the code to make the calendar appear?
HTML:
<script type="text/javascript">
function Confirm() {
var confirm_value = document.createElement("INPUT");
confirm_value.type = "hidden";
confirm_value.name = "confirm_value";
if (confirm("Do you want to proceed ?")) {
confirm_value.value = "Yes";
} else {
confirm_value.value = "No";
}
document.forms[0].appendChild(confirm_value);
}
</script>
<script type="text/javascript">
function ConfirmEvent() {
var confirm_value_event = document.createElement("INPUT");
confirm_value_event.type = "hidden";
confirm_value_event.name = "confirm_value_event";
if (confirm("Do you want to proceed ?")) {
confirm_value_event.value = "Yes";
} else {
confirm_value_event.value = "No";
}
document.forms[0].appendChild(confirm_value_event);
}
</script>
<style type="text/css">
.style1 {
font-weight: bold;
width: 120px;
}
.style2 {
color: Blue;
font-weight: bold;
text-decoration: underline;
height: 25px;
}
.style5 {
color: Blue;
font-weight: bold;
text-decoration: underline;
}
.style6 {
width: 96px;
}
.style7 {
width: 150px;
}
</style>
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"></asp:ToolkitScriptManager>
<div id='calendar'>
</div>
VB.NET:
Public Class _Default
Inherits System.Web.UI.Page
Public eventstring As String
"server=xxx.xxx.x.x\SQLEXPRESS;database=attendance;uid=ab;pwd=abcde;"
Dim Conn As SqlConnection
Dim da As SqlDataAdapter
Dim cmd As SqlCommand
Dim rdmysql As SqlDataReader
Dim strsql As String
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim lbl As Label = Master.FindControl("lblHeader")
lbl.Text = "IT Attendance"
Dim startdate As String = Format(Now, "yyyy-MM-dd")
If txtStartDate.Value = "" Then txtStartDate.Value = startdate
If txtEndDate.Value = "" Then txtEndDate.Value = startdate
If txtStartEvent.Value = "" Then txtStartEvent.Value = startdate
If txtEndEvent.Value = "" Then txtEndEvent.Value = startdate
Conn = New SqlConnection
Conn.ConnectionString = ConnStr
Conn.Open()
eventstring = ""
strsql = "SELECT * FROM record;"
cmd = New SqlCommand
cmd.Connection = Conn
cmd.CommandText = strsql
rdmysql = cmd.ExecuteReader
Do While rdmysql.Read = True
eventstring = eventstring & "{title: '" & rdmysql.GetString(1) & " - " & rdmysql.GetString(3) & "', start: '" & rdmysql.GetString(2) & "', color: 'yellow', borderColor: 'black', textColor: 'black'},"
Loop
cmd.Dispose()
rdmysql.Close()
strsql = "SELECT * FROM event;"
cmd = New SqlCommand
cmd.Connection = Conn
cmd.CommandText = strsql
rdmysql = cmd.ExecuteReader
Do While rdmysql.Read = True
eventstring = eventstring & "{title: '" & rdmysql.GetString(1) & "', start: '" & rdmysql.GetString(2) & "', color: 'skyblue', textColor: 'black', borderColor: 'black'},"
Loop
cmd.Dispose()
rdmysql.Close()
eventstring = Mid(eventstring, 1, Len(eventstring) - 1)
Anyone can help me to solve this problem?
Related
I am using ASP.net GridView. There are check boxes that filters the results after selecting the checkbox and clicking a search button but I want to remove the button to filter automatically after selecting the check boxes.
The contents display in the gridview are from a database table
ASP
<b><label style="font-size:25px">Brand</label></b>
<asp:CheckBoxList ID="CheckBoxList1" runat="server" DataSourceID="SqlDataSource2" DataTextField="SBrand" DataValueField="SBrand">
</asp:CheckBoxList>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:DefaultConnection %>" SelectCommand="SELECT DISTINCT [SBrand] FROM [Stock]"></asp:SqlDataSource>
C#
protected void gvStock_SelectedIndexChanged(object sender, EventArgs e)
{
string id = gvStock.SelectedRow.Cells[0].Text;
Response.Redirect("Details.aspx?ID=" + id);
}
protected void Button1_Click(object sender, EventArgs e)
{
string chkbox = "";
Label1.Visible = false;
for (int i = 0; i < CheckBoxList1.Items.Count; i++)
{
if (CheckBoxList1.Items[i].Selected)
{
if (chkbox == "")
{
chkbox = "'" + CheckBoxList1.Items[i].Text + "'";
}
else
{
chkbox += "," + "'" + CheckBoxList1.Items[i].Text + "'";
}
Label1.Text = chkbox;
string mainconn = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
SqlConnection sqlconn = new SqlConnection(mainconn);
string sqlquery = "SELECT [pCode],[pID],[bCode], [SBrand], [SDescription], [sCost] , [sPrice] , [SType] , [sSupplierName] , [sSupplierDirect] FROM Stock where SBrand in (" + Label1.Text + ")";
SqlCommand sqlcomm = new SqlCommand(sqlquery, sqlconn);
sqlconn.Open();
SqlDataAdapter sda = new SqlDataAdapter(sqlcomm);
DataTable dt = new DataTable();
sda.Fill(dt);
this.gvStock.DataSource = dt;
this.gvStock.DataBind();
}
}
}
ASPX
<asp:CheckBoxList ID="CheckBoxList1" runat="server" DataSourceID="SqlDataSource2" DataTextField="SBrand" DataValueField="SBrand" AutoPostBack="True" OnSelectedIndexChanged="CheckBoxList1_SelectedIndexChanged">
.CS
protected void CheckBoxList1_SelectedIndexChanged(object sender, EventArgs e)
{
string chkbox = "";
Label1.Visible = false;
for (int i = 0; i < CheckBoxList1.Items.Count; i++)
{
if (CheckBoxList1.Items[i].Selected)
{
if (chkbox == "")
{
chkbox = "'" + CheckBoxList1.Items[i].Text + "'";
}
else
{
chkbox += "," + "'" + CheckBoxList1.Items[i].Text + "'";
}
Label1.Text = chkbox;
string mainconn = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
SqlConnection sqlconn = new SqlConnection(mainconn);
string sqlquery = "SELECT [pCode],[pID],[bCode], [SBrand], [SDescription], [sCost] , [sPrice] , [SType] , [sSupplierName] , [sSupplierDirect] FROM Stock where SBrand in (" + Label1.Text + ")";
SqlCommand sqlcomm = new SqlCommand(sqlquery, sqlconn);
sqlconn.Open();
SqlDataAdapter sda = new SqlDataAdapter(sqlcomm);
DataTable dt = new DataTable();
sda.Fill(dt);
this.gvStock.DataSource = dt;
this.gvStock.DataBind();
}
}
}
Using asp.net, I want to upload multiple files using single file upload option, but I'm getting, System.Web.UI.WebControls.FileUpload' does not contain a definition for 'HasFiles' and no extension method error.
My code:
<%-- ed: some styles removed for readability. --%>
<div class="col-md-3">
<asp:Label ID="lblattach" runat="server" Text="Attach File:"></asp:Label>
<asp:FileUpload ID="FileUpload1" runat="server" AllowMultiple="true"></asp:FileUpload>
</div>
if (FileUpload1.HasFiles)
{
if (FileUpload1.FileName.EndsWith(".pdf") ||
FileUpload1.FileName.EndsWith(".PDF") ||
FileUpload1.FileName.EndsWith(".doc") ||
FileUpload1.FileName.EndsWith(".DOC") ||
FileUpload1.FileName.EndsWith(".docx") ||
FileUpload1.FileName.EndsWith(".DOCX"))
{
foreach (HttpPostedFile PostedFiles in FileUpload1.PostedFiles)
{
FileInfo TheFile =
new FileInfo(MapPath("~/Ebooks") + "\\" + FileUpload1.FileName);
if (TheFile.Exists)
{
Label1.Visible = true;
Label1.Text = "File '" + FileUpload1.FileName + "' Already Exists";
}
else
{
string fileName = Path.GetFileName(PostedFiles.FileName);
PostedFiles.SaveAs(Server.MapPath("~/Ebooks") + "\\" + fileName);
{
Con.Open();
string sql1 = "Sp_InsertEbookLinks";
SqlCommand cmd = new SqlCommand(sql1, Con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("#linkName", link);
cmd.Parameters.AddWithValue("#fileName", FileUpload1.FileName);
cmd.Parameters.AddWithValue("#BatchCode", ddlbatch.SelectedValue);
cmd.Parameters.AddWithValue("#CourseCode", ddlcourse.SelectedValue);
cmd.Parameters.AddWithValue("#SemesterCode", ddlSemester.SelectedValue);
cmd.Parameters.AddWithValue("#SubjectCode", ddlsubject.SelectedValue);
cmd.Parameters.AddWithValue("#ActiveInactive", chkbxactinact.Checked);
cmd.Parameters.AddWithValue("#lastModUserCod", 1);
cmd.ExecuteNonQuery();
Con.Close();
ScriptManager.RegisterStartupScript(this, GetType(), "Popup",
"Successalert('Data Inserted Successfully');", true);
LoadData();
txtlink.Text = "";
ddlbatch.SelectedValue = "0";
ddlcourse.SelectedValue = "0";
ddlSemester.SelectedValue = "0";
ddlsubject.SelectedValue = "0";
Label1.Visible = false;
}
}
}
I'm trying to send email in asp.net, it works find and send email to GMAIL and YAHOO mails but not working on HOTMAIL or OUTLOOK account.
Here is code...
Dim pass As String = RandomPassword.Generate(8, 10)
ta.insertuser(txtuser.Text, pass, txtfname.Text, txtlname.Text, txtemail.Text, droprole.SelectedValue, radiostatus.SelectedValue, DateTime.Now())
Dim senderma As New MailAddress("client#karacode.ir", "karacode")
Dim recipientma As New MailAddress(txtemail.Text)
Dim mm As New MailMessage(senderma, recipientma) With {
.Subject = "Account Details",
.SubjectEncoding = System.Text.Encoding.UTF8,
.Body = "<div style='font-family: tahoma; font-size: 10pt; padding: 1em; direction:rtl; text-align: justify; line-height: 2;'>" & "Dear User" & " " & txtfname.Text & " " & txtlname.Text & "<br />" & "You're most welcom to KARACODE" & "<br /><br />" & "Your account information<br /><br />" & "Username : <br />" & txtuser.Text & "<br /><br />" & "Password : <br />" & pass & "</div>",
.BodyEncoding = System.Text.Encoding.UTF8,
.IsBodyHtml = True
}
Dim cred As New System.Net.NetworkCredential With {
.UserName = "client#karacode.ir",
.Password = "Client164418054545"
}
Dim smtp As New SmtpClient With {
.Host = "webmail.karacode.ir",
.EnableSsl = False,
.UseDefaultCredentials = True,
.Credentials = cred,
.Port = 25
}
smtp.Send(mm)
Please gives the tips to solve the problem.
MANY THANKS
I'm a new member here. I want to ask something. Best regards for everyone of you to answer my questions. Sorry for my bad English. I'm from Indonesia.
I have two radiobutton, two textbox, two datagridview and one button. The scenario is my first textbox is Input by InvoiceNumber and the second Textbox input by AccountNumber. My question is when I input by Invoicenumber and I click Button Search the datagridview for Invoicenumber will show and when I input by Accountnumber the datagridview for Accounrnumber will show. This is my Code:
Default.aspx.vb: (Updated below to display code correctly by Piyush Khatri)
Protected Sub Submit_Click(sender As Object, e As EventArgs) Handles Submit.Click
periode = cbbulan.SelectedValue.ToString + Microsoft.VisualBasic.Right(cbtahun.Text, 2).ToString
If txtseacrh.Text Then
Me.BindGrid(txtseacrh.Text, periode)
tampildata()
Label3.Text = "Consignee : "
Label4.Text = "Address : "
Label5.Text = "Product :"
End If
Me.BindGrid2(txtsearch2.Text)
End Sub
Private Sub BindGrid(RefNo As String, periode As String)
Dim constr As String = ConfigurationManager.ConnectionStrings("dbCon").ConnectionString
Using con As New SqlConnection(constr)
Using cmd As New SqlCommand()
cmd.CommandText = "Declare #awb As varchar(50)
Select #awb=awb from msdetail md inner join msdata mt On mt.PuNo=md.Puno
where md.Puno='" & RefNo & "'
Select '1' as no, Convert(varchar(12), pudate, 103) As Date,CONVERT(varchar(8), pudate,8) as time,'PU' AS status,'' as Recipient, '' as Remaks,'' as PIC from MsDetail where AWB=#awb
And Periode='" & periode & "'
union
Select '2' as no, CONVERT(varchar(12),pudatein,103) as date,CONVERT(varchar(8), pudatein,8) as time,'DE' AS status,'' as Recipient, '' as Remaks, IdUser as PIC from MsDetail where AWB=#awb
And Periode='" & periode & "'
UNION
Select '3' as no, CONVERT(varchar(12),stdate,103) as date,CONVERT(varchar(8), stdate,8) as time,StStt AS status,StPenerima as Recipient,StRel as Remaks, st.IdUser as PIC from status st
inner Join MsDetail md on md.AWB=st.AWB where md.AWB=#awb And Periode='" & periode & "' order by no"
cmd.Connection = con
Dim dt As New DataTable()
Using sda As New SqlDataAdapter(cmd)
sda.Fill(dt)
GridView1.DataSource = dt
GridView1.DataBind()
End Using
End Using
End Using
End Sub
Private Sub BindGrid2(Puno As String)
Dim constr As String = ConfigurationManager.ConnectionStrings("dbCon").ConnectionString
Using con As New SqlConnection(constr)
Using cmd As New SqlCommand()
cmd.CommandText = "select Refno,Field1,(CONVERT (varchar(10),PuDate,103)) as PuDate,(Convert (varchar(10),Pudatein,103))as Pudatein,mdcompany,MdAdd1,mdadd2,mdadd3,mdadd4,StStt,(CONVERT (varchar(10),StDate,103)) as StDate,StPenerima,StRel from MsDetail inner join MsData on MsDetail.PuNo=MsData.PuNo
left join Status on MsDetail.AWB=Status.AWB where MsData.Refno='" & Puno & "'"
cmd.Connection = con
Dim dt As New DataTable()
Using sda As New SqlDataAdapter(cmd)
sda.Fill(dt)
GridView2.DataSource = dt
GridView2.DataBind()
End Using
End Using
End Using
End Sub
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
'Fill Years
For i As Integer = Year(Now) - 1 To Year(Now)
cbtahun.Items.Add(i.ToString())
Next
cbtahun.Items.FindByValue(System.DateTime.Now.Year.ToString()).Selected = True 'set current year as selected
End If
End Sub
Protected Sub cbbulan_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cbbulan.SelectedIndexChanged
'Session["cbbulan"]=DropDownList.SelectedValue;
End Sub
Private Sub koneksi()
strconn = WebConfigurationManager.ConnectionStrings("dbCon").ConnectionString
MyCn = New SqlConnection(strconn)
If MyCn.State <> Data.ConnectionState.Closed Then MyCn.Close()
MyCn.Open()
End Sub
Private Sub tampildata()
koneksi()
Dim sql As String
Dim cmd As SqlCommand
Dim dread As SqlDataReader
' Dim constr As String = ConfigurationManager.ConnectionStrings("a").ConnectionString
sql = "select prname,MdName,isnull(MdAdd1,'') + ' ' + isnull(MdAdd2,'') + ' ' + isnull(MdAdd3,'') as ALAMAT from MsData inner join MsDetail on MsDetail.PuNo=MsData.PuNo
Left Join Produk on MsDetail.Code=Produk.Code where msdata.PuNo='" & txtseacrh.Text & "'"
cmd = New SqlCommand(Sql, MyCn)
dread = cmd.ExecuteReader
If dread.HasRows Then
While dread.Read = True
Label1.Text = dread.Item("mdName").ToString
Label2.Text = dread.Item("ALAMAT").ToString
Label6.Text = dread.Item("PrName").ToString
End While
dread.Close()
End If
End Sub
Try something like this
HTML Code (.aspx page)
<div>
<asp:TextBox ID="txtInvoice" runat="server" />
<asp:TextBox ID="txtAccountNo" runat="server" />
<asp:Button id="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click" />
</div>
<div>
<asp:GridView ID="gv" runat="server" AutoGenerateColumns="true" />
</div>
**Code Behind**
protected void btnSubmit_Click(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(txtInvoice.Text.Trim())) {
gv.DataSource = getInvoiceDetails(txtInvoice.Text);
gv.DataBind();
}
else if (!string.IsNullOrEmpty(txtAccountNo.Text.Trim()))
{
gv.DataSource = getAccountDetails(txtInvoice.Text);
gv.DataBind();
}
}
private DataTable getInvoiceDetails(string invoiceNo) {
DataTable dt = new DataTable();
using (SqlConnection con = new SqlConnection(connectionString)) {
using (SqlCommand cmd = new SqlCommand("YourQueryToGetInvoiceDetails")) {
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
adapter.Fill(dt);
return dt;
}
}
}
private DataTable getAccountDetails(string invoiceNo)
{
DataTable dt = new DataTable();
using (SqlConnection con = new SqlConnection(connectionString))
{
using (SqlCommand cmd = new SqlCommand("YourQueryToGetAmountDetails"))
{
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
adapter.Fill(dt);
return dt;
}
}
}
I am uploading excel in asp.net. but one column not read .
protected void btnUpload_Click(object sender, EventArgs e)
{
SqlConnection myconn = new SqlConnection(sqlConnectionString);
if (FileUpload1.HasFile)
{
string paramExcelSheetName = Path.GetFileName(FileUpload1.PostedFile.FileName);
FileUpload1.PostedFile.Equals(Server.MapPath("~/UploadExcel/" + paramExcelSheetName));
string strFileType = Path.GetExtension(FileUpload1.FileName).ToLower();
string path = string.Concat(Server.MapPath("~/UploadExcel/" + FileUpload1.FileName));
if (File.Exists(path))
{
File.Delete(path);
}
if (strFileType.Trim() == ".xls")
{
excelConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path + ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=2\"";
}
else if (strFileType.Trim() == ".xlsx")
{
excelConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Persist Security Info=False;Extended Properties=\"Excel 12.0;HDR=Yes;IMEX=2\"";
}
FileUpload1.SaveAs(path);
OleDbConnection conn = new OleDbConnection(excelConnectionString);
query = "SELECT * FROM [Sheet1$] ";
conn.Open();
OleDbCommand cmd = new OleDbCommand(query, conn);
OleDbDataReader oledbdr = cmd.ExecuteReader();
#region readline by line
if (oledbdr.HasRows)
{
while (oledbdr.Read())
{
if (!oledbdr.IsDBNull(0))
{
if (!oledbdr.IsDBNull(0))
{
sr =Convert.ToInt32( oledbdr["SrNo"].ToString());
}
else
{
}
if (!oledbdr.IsDBNull(0))
{
certificate = oledbdr["CertificateNo"].ToString();
}
else
{
}
if (!oledbdr.IsDBNull(0))
{
cr = oledbdr["CR"].ToString();
}
else
{
}
//if (!oledbdr.IsDBNull(0))
//{
// cr = oledbdr["Pass"].ToString();
//}
//else
//{
//}
#region
SqlCommand myCommand = new SqlCommand("INSERT INTO test1 (SrNo,CertificateNo,CR) VALUES('" + sr + "','" +certificate+ "','" + cr + "')", myconn);
try
{
myconn.Open();
myCommand.ExecuteNonQuery();
myconn.Close();
}
catch (Exception ex)
{
myconn.Close();
}
#endregion
}
}
}
#endregion
conn.Close();
}
}
one column certificate not read certificate value like 737737373737/En2
try this code.
query = "SELECT SrNo,CertificateNo,CR FROM [Sheet1$] ";
FileUpload1.SaveAs(Server.MapPath("~/uploadmedicine/") + FileUpload1.FileName);
if (FileUpload1.PostedFile != null)
{
string path = FileUpload1.PostedFile.FileName;
string connectString = #"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Server.MapPath("~/uploadmedicine/") + FileUpload1.FileName + ";Extended Properties=\"Excel 12.0 Xml;HDR=YES;IMEX=1;\"";
OleDbConnection conn = new OleDbConnection(connectString);
OleDbDataAdapter da = new OleDbDataAdapter("SELECT SrNo,CertificateNo,CR from [Sheet1$]", conn);
}