the error says "you might be missing a using directive".
User 10307097
Posts
-
I am trying to send an automated email from the company's exchange server, but it doesn't recognize the "ExchangeService " and "EmailMessage" in the following C# code -
I am trying to send an automated email from the company's exchange server, but it doesn't recognize the "ExchangeService " and "EmailMessage" in the following C# codeThis is my code. Please help. string from = "myemail@myexchangeserver.com"; string to = "recipient@email.com"; ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP1);//error here service.AutodiscoverUrl(from); EmailMessage message = new EmailMessage(service);// Error here message.Subject = "Email Subject"; message.Body = richTextBox1.Text; message.ToRecipients.Add(to); message.Save(); message.SendAndSaveCopy();
-
I am trying to update database from datagridview using stored procedure and it keeps on saying The stored procedure expects a parameter BookID which was not supplied. Below is my codeMy stored procedure ALTER PROCEDURE [dbo].[UpdateAllBooks] @BookID int OUTPUT, @GeneralID INT OUTPUT, @FileName nvarchar(max), @FilePath nvarchar(max), @FileSize nvarchar(max), @DateAdded date, @MediaLength nvarchar(max), @MediaType nvarchar(max), @MediaSubType nvarchar(max), @Thumbnail image, @DateAcquired datetime, @AuthorName nvarchar(50), @ISBN nvarchar(max), @Title nvarchar(max), @Genre nvarchar (max), @Series nvarchar(max), @YearOfPublication date, @Description text AS BEGIN Update dbo.General SET FileName = @FileName, FilePath = @FilePath, FileSize = @FileSize, DateAdded = @DateAdded, MediaLength = @MediaLength, MediaType = @MediaType, MediaSubType = @MediaSubType, Thumbnail = @Thumbnail, DateAcquired = @DateAcquired Where GeneralID = @GeneralID Update dbo.Books SET AuthorName = @AuthorName, ISBN = @ISBN, Title = @Title, Genre = @Genre, Series = @Series, YearOfPublication = @YearOfPublication , Description = @Description Where BookID = @BookID END My code private void Update_Click(object sender, EventArgs e) { if (connect.State == ConnectionState.Open) { connect.Close(); } connect.Open(); cmd = new SqlCommand("dbo.UpdateAllBooks", connect); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@BookID", SqlDbType.Int, 4, "BookID"); cmd.Parameters.Add("@GeneralID", SqlDbType.Int,4,"GeneralID"); cmd.Parameters.Add("@FileName", SqlDbType.NVarChar, 50, "FileName"); cmd.Parameters.Add("@AuthorName", SqlDbType.NVarChar, 50,"AuthorName"); cmd.Parameters.Add("@ISBN", SqlDbType.NVarChar, 50, "ISBN"); cmd.Parameters.Add("@Title", SqlDbType.NVarChar, 50, "Title"); cmd.Parameters.Add("@Genre", SqlDbType.NVarChar, 50, "Genre"); cmd.Parameters.Add("@Series", SqlDbType.NVarChar, 50, "Series"); cmd.Parameters.Add("@YearOfPublication", SqlDbType.Date, 50, "YearOfPublication"); cmd.Parameters.Add("@Thumbnail", SqlDbType.Image); cmd.Parameters.Add("@Description", SqlDbType.NVarChar, 50, "Description"); cmd.Parameters.Add("@FileSize", SqlDbType.NVarChar, 50, "FileSize"); cmd.Parameters.Add("@FilePath", SqlDbType.NVarChar, 50, "FilePath"); cmd.Parameters.Add("@DateAdded", S
-
I am trying to dispaly database values based on the combobox selection and i get this error "Data is null. this method cannot be called on null values"this is my code private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { try { if (connect.State == ConnectionState.Open) { connect.Close(); } connect.Open(); String query = "select * from V_General_Books where FileName= '" + FileNameComboBox.Text + "'";// '" + textBox2.Text + "' and UserName= '" + textBox3.Text + "' "; cmd = new SqlCommand(query, connect); dr = cmd.ExecuteReader(); if(dr.Read()) { string bookid = dr.GetInt32(10).ToString(); BookIDTextBox.Text = bookid; string generalid = dr.GetInt32(0).ToString(); GeneralIDTextBox.Text = generalid; string isbn = dr.GetString(12); ISBNTextBox.Text = isbn; string author = dr.GetString(11); AuthorNameTextBox.Text = author; string genre = dr.GetString(16); GenreTextBox.Text = genre; byte[] x = (byte[])dr[8]; MemoryStream ms = new MemoryStream(x); pictureBox1.Image = Image.FromStream(ms); string series = dr.GetString(15); SeriesTextBox.Text = series; string year = dr.GetString(14); YearOfPublicationTextBox.Text = year; string dateacquired = dr.GetString(9); DateAcquiredTextBox.Text = dateacquired; string filename = dr.GetString(1); FileNameTextBox.Text = filename; string filepath = dr.GetString(2); FilePathTextBox.Text = filepath; string length = dr.GetString(5); MediaLengthTextBox.Text = length; string type = dr.GetString(6); MediaTypeTextBox.Text = type; string subtype = dr.GetString(7); MediaSubTypeTextBox.Text = subtype; DateTime dateadded = dr.GetDateTime(4); DateAddedDateTimePicker.MaxDate = dateadded; string filesize
-
I am trying to update information using combobox to the database and the error it gives is "Object reference not set to an instance of an object"Below is my stored procedure ALTER PROCEDURE [dbo].[sp_Workflow] @TicketID int output, @StaffID int output, @Department nvarchar (50), @FirstName nvarchar (50), @TicketStatusID int output, @TicketStatus nvarchar (50), @TicketPriorityID int output, @TicketPriority nvarchar (50) AS BEGIN UPDATE dbo.Staff SET FirstName = @FirstName, Department = @Department WHERE StaffID= @StaffID UPDATE dbo.TicketStatus SET TicketStatus = @TicketStatus WHERE TicketStatusID =@TicketStatusID UPDATE dbo.TicketPriority SET TicketPriority = @TicketPriority WHERE TicketPriorityID =@TicketPriorityID END T :) his is my code private void Updatebutton_Click(object sender, EventArgs e) { con.Open(); SqlCommand cmd = con.CreateCommand(); cmd = new SqlCommand("sp_Workflow", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@TicketID", System.Data.SqlDbType.Int).Value = TicketIDcomboBox.ToString(); cmd.Parameters.Add("@Department", System.Data.SqlDbType.NVarChar, 50).Value = MoveToDepartmentcomboBox.SelectedValue.ToString(); cmd.Parameters.Add("@FirstName", System.Data.SqlDbType.NVarChar, 50).Value = StaffcomboBox.SelectedValue.ToString(); cmd.Parameters.Add("@TicketStatus", System.Data.SqlDbType.NVarChar, 50).Value = ChangeTicketStatuscomboBox.SelectedValue.ToString(); cmd.Parameters.Add("@TicketPriorty", System.Data.SqlDbType.NVarChar, 50).Value = ChangeTicketPrioritycomboBox.SelectedValue.ToString(); MessageBox.Show("Are you sure you want to update?"); cmd.ExecuteNonQuery(); MessageBox.Show("Ticket Updated"); con.Close(); } }
-
Update stored procedure doesn't update, it keeps on saying info modification fails, please helpprivate void Update_Click(object sender, EventArgs e) { try { if (connect.State == ConnectionState.Open) { connect.Close(); } connect.Open(); SqlCommand cmd = connect.CreateCommand(); cmd = new SqlCommand("sp_UpdateDepartStaff", connect); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@StaffID", SqlDbType.Int).Value = logInIDTextBox.Text.ToString(); cmd.Parameters.AddWithValue("@LogInID", SqlDbType.Int).Value = staffIDTextBox.Text.ToString(); cmd.Parameters.AddWithValue("@StaffRoleID", SqlDbType.Int).Value = staffRoleIDTextBox.Text.ToString(); cmd.Parameters.AddWithValue("@FirstName", SqlDbType.NVarChar).Value = firstNameTextBox.Text; cmd.Parameters.AddWithValue("@LastName", SqlDbType.NVarChar).Value = lastNameTextBox.Text; cmd.Parameters.AddWithValue("@UserName", SqlDbType.NVarChar).Value = userNameTextBox.Text; cmd.Parameters.AddWithValue("@Password", SqlDbType.NVarChar).Value = passwordTextBox.Text; cmd.Parameters.AddWithValue("@Email", SqlDbType.NVarChar).Value = emailTextBox.Text; cmd.Parameters.AddWithValue("@Phone", SqlDbType.NVarChar).Value = phoneTextBox.Text; cmd.Parameters.AddWithValue("@StaffRole", SqlDbType.NVarChar).Value = staffRoleTextBox.Text; cmd.Parameters.AddWithValue("@Department", SqlDbType.NVarChar).Value = departmentTextBox.Text; // cmd.Parameters.Add(new SqlParameter("@ProfilePic", SqlDbType.Image)); MemoryStream MemStream = new MemoryStream(); byte[] DataPic_Update = null; this.profilePicPictureBox.Image.Save(MemStream, ImageFormat.Png); DataPic_Update = MemStream.GetBuffer(); MemStream.Read(DataPic_Update, 0, DataPic_Update.Length); // image content SqlParameter photo = new SqlParameter("@profilePic", SqlDbType.Image); photo.Value = DataPic_Update; cmd.Parameters.Add(photo); int temp = 0; temp = cmd.ExecuteNonQuery(); if (temp > 0) { connect.Close(); MessageBox.Show("Your info upda